Archive for the ‘wordpress’ Category

21
Jul
function check_for_shortcode($posts) {
    if ( empty($posts) )
        return $posts;

    $flag = false;

    foreach ($posts as $post) {
        if ( stripos($post->post_content, '[YOUR_SHORTCODE_HERE') )
            $flag = true;
            break;
        }

    if ($flag){
        //add scripts and styles here eg:
        //wp_enqueue_script
        //wp_enqueue_style
    }
    return $posts;
}
add_action('the_posts', 'check_for_shortcode');

, ,

28
Jun

is_front_page() returns true when on the site front page (what is commonly referred to as the “home” page).
is_front_page() returns true when on the site front page, whether the front page is set to display the Blog Posts Index or a static Page.
is_home() returns true when displaying the Blog Posts Index.
is_home() returns true when displaying the Blog Posts Index, whether on the Front Page, or on a static Page.

, ,

01
May

we can check whther the user logged in or not using worpress api function.

<?php
if ( is_user_logged_in() ) {
    echo 'Welcome, registered user!';
} else {
    echo 'Welcome, visitor!';
};
?>

, , , , ,

28
Apr

Here we can convert any strings to uppercase using wordpress functions.

add_filter('the_title', strtoupper);

27
Apr

WordPress 1.4 for android is now available in Android Market. Here’s the features:

1. Post Scheduling:- Users can easily set the publish date and time in the app when creating a post.

2. Post Password:- Password field to protect post content.

3. HTTP Authentication Support:- Support for entering the authentication credentials in the blog settings so that you can manage your blog through the app.

4. Added Today Status option

5. Unapproved comments in yellow tint color.

6. Secure password storage to the local database

, , , ,

18
Apr

You can send mail from a wordpress blog to anyone using wp_mail().

<?php
$to = 'user@example.com';
$subject = 'Hello from my blog!';
$message = 'i am emailing you!'

$mail = wp_mail($to, $subject, $message);

if($mail) echo 'Your message has been sent!';
else echo 'There was a problem sending your message. Please try again.';
?>

, , , , ,

09
Mar

Script Injection is computer bug that causes exploitation to our site.We can overcome this script injection by making small tweaks in our .htaccess file.

Before editing your .htaccess file.Make sure that you have a backup of your file.Paste the following code in your .htaccess file.

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]

, , ,

07
Mar

These accept a string as an argument. For example:

__("Hello World")
_e("Hello World")

The only functional difference between the two methods is that _e() echoes the string and () simply returns the string. () is used when you want to supply a string to a function. _e() is used when you want to output the string as part of your XHTML.

07
Feb

There several reasons and scenarios which arise to control the access of the web robots or web crawlers or simple spiders, to our website. Like  Google-bot (Google Spider) visiting our website,  spam bots too will visit. Spam bots usually visit and collect private information from our website. When a robot crawls our website it uses a considerable amount of the website’s bandwidth too! It is easy to control robots by disallowing the access of the web robots to our website through the usage of a simple ‘robots.txt’ file.

Creating a robots.txt:

Open a new File in any Text Editor Like Notepad.

The rules in the robots.txt file are entered in a ‘field’: ‘value’ pair.
<field>:<value>

<field>

Can have possible two values: allow or disallow for a particular URL

<value>

An URL or URI that the access or rule is specified.

Eg.:

User-agent: *
Disallow: /private-folder

Samples:

If  we want to exclude all the search engine robots from indexing our entire website , then do enter the following into the robots.txt file:

User-agent: *
Disallow: /

If we want to exclude all the bots from a certain directory within our website, we would write the following:

User-agent: *
Disallow: /aboutme/

For multiple directories, we add on similar Disallow values

User-agent: *
Disallow: /aboutme/
Disallow: /stats/

Access to specific documents can also be specifoed.

User-agent: *
Disallow: /myFolder/name_me.html

If we want to disallow a specific search engine bot from indexing our website,

User-agent: Robot_Name
Disallow: /

Advantages of Using Robots.txt:

  • Avoid Wastage of Server Resources
  • Save Bandwidth
  • Removes Clutter and complexity from Web Statistics and more smooth anlytics
  • Refusing a specific Robots

Common Errors and mistakes in robots.txt:

  1. It is not Guaranteed to Work
    Instead use .htaccess file in combination with .htpasswd
  2. It is not a method to protect Secret Directories
    Any bot or agent can access robots.txt. Don’t put any secret directories or files in it.
  3. Only One Directory/File per Disallow line

The rules are singular in sense. One rules or fields contains only one value.

, , , , , , , , , , , , , , , , , ,

03
Feb

For solving this problem.open wp-settings.php and comment out the following line:

// Check if we’re in maintenance mode.
wp_maintenance();

it’s on line 50, simply make it:

// Check if we’re in maintenance mode.
// wp_maintenance();

, ,