Monday, December 10, 2012

Important Methods for On Page Optimization

The following process need to do for on page optimization in SEO.

    Keyword Research and Analysis
    Keyword Density
    Title Tag (Page Title Optimization)
    Page Specific Meta Tag Creation
    Anchor Text Optimization
    Alt Tag Optimization
    Submission of XML Sitemap
    Content Placement  
    Implementation of Google Analytic
    Search Engine Verification from Google, Yahoo and MSN
    Creation and Submission of ROR.xml
    Creation of Proper Link Structure
    Implementation of 301 Permanent Redirect
    Optimization of Search Engine Essential Files (robots.txt, urllist.txt, sitemap.xml)
    Creating micro-formats like hcard integration, hrview integration, vCard integration.

Thursday, December 6, 2012

How to get the first link in wordpress posts

How to get the first link in wordpress posts

Please follow the code structure to get the first link from a post.


To make this happen just paste this code into your functions.php file.

function get_content_link( $content = false, $echo = false ){
    if ( $content === false )
        $content = get_the_content();

    $content = preg_match_all( '/hrefs*=s*["']([^"']+)/', $content, $links );
    $content = $links[1][0];

    if ( empty($content) ) {
        $content = false;
    }

    return $content;
}

The above function finds the first link in the post and returns that link to you. So In this following way, we can link the title(or whatever) to this place, as describe below:

<h2><a href="<?php echo get_content_link( get_the_content() ); ?>"><?php the_title(); ?></a></h2>

Tuesday, November 27, 2012

How to create a Pinterest "pin it" button for your WordPress blog

How to create a Pinterest "pin it" button for your WordPress blog

Just paste the following code where you like the "Pin It" button to be displayed. But remeber that this code must be inserted within the loop.

<a href="http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' ); echo $thumb['0']; ?>&description=<?php the_title(); ?>" class="pin-it-button" count-layout="horizontal">Pin It</a>

Now footer.php file and add the pinterest JavaScript code:

<script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>

Thursday, November 22, 2012

Automatic “Nofollow” for external links in post content of wordpress

Automatic “Nofollow” for external links in post content of wordpress

WordPress hack: Automatic “Nofollow” for external links in post content of wordpress

WordPress does not automatically by default add a rel=”nofollow” attribute to its external links within the post content. But If you want to add this attribute, the following solution help you to force WordPress to add the rel=”nofollow” attribute to every external link.

To make this work just Paste the following code in the functions.php file. Now save the file, you can see that all external links in your post content will be changed to nofollow.

add_filter('the_content', 'auto_nofollow');

function auto_nofollow($content) {
    //return stripslashes(wp_rel_nofollow($content));

    return preg_replace_callback('/<a>]+/', 'auto_nofollow_callback', $content);
}

function auto_nofollow_callback($matches) {
    $link = $matches[0];
    $site_link = get_bloginfo('url');

    if (strpos($link, 'rel') === false) {
        $link = preg_replace("%(href=S(?!$site_link))%i", 'rel="nofollow" $1', $link);
    } elseif (preg_match("%href=S(?!$site_link)%i", $link)) {
        $link = preg_replace('/rel=S(?!nofollow)S*/i', 'rel="nofollow"', $link);
    }
    return $link;
}

How to remove WordPress version number from pages and feeds

How to remove WordPress version number from pages and feeds

WordPress always publicly display wordpress version number in RSS and Atom feeds by default. With the following solution we can remove those wordpress version number from all our blog feeds.

You need to just use this code in functions.php file

add_filter('the_generator', 'digwp_complete_version_removal');
function digwp_complete_version_removal() {
    return '';
}

Sunday, October 28, 2012

Search within a specific post type only in Wordpress

Search within a specific post type only in Wordpress

In wordpress, when a user/visitor search website using WordPress built-in search function, wordpress always search through all post types. But sometimes we may need to be able to search only within a wordpress specific post type.The following code example will help to display that.


In the following code allows to modify WordPress search engine to search only within a specific post type. To work like that Just update the code with your post type name on line 4, then paste it into your theme functions.php file.


function SearchFilter($query) {
  if ($query->is_search) {
    // Insert the specific post type you want to search
    $query->set('post_type', 'feeds');
  }
  return $query;
}

// This filter will jump into the loop and arrange our results before they're returned
add_filter('pre_get_posts','SearchFilter');

 

Friday, September 14, 2012

Get post content by ID in Wordpress

When we building a custom theme in wordpress, sometimes we need to get the title or content from a specific post in wordpress. Also sometimes, using a custom loop is the better option for us, but its hard when we need to get information from a specific post only,follow the instruction to overcome that



Just use the get_post_field() function. You can get the post content from it. Fine the following example which will display the content of the post with id $post_id:

echo get_post_field('post_content', $post_id);

Also, the function can be used to get other fields from the post. See the codex page for reference in wordpress.

Tuesday, August 21, 2012

How to create a dropdown menu of tags in wordpress

How to create a dropdown menu of tags in wordpress

Like wp_dropdown_categories() function which display the categories in a dropdown menu, there’s no built in function to display dropdown menu of tags in wordpress. But to display tags in a dropdown as well, Let’s use wp_dropdown_categories() and modify it in order to be able to display tags in a dropdown menu. Just paste the following code where you want the dropdown menu to be displayed. Here we can use our own taxonomy: Just modify the code on line 5 according to your needs.


<h2><?php _e('Posts by Tags'); ?></h2>
<form action="<?php bloginfo('url'); ?>/" method="get">
<div>
<?php
$select = wp_dropdown_categories('taxonomy=post_tag&show_option_none=Select tag&show_count=1&orderby=name&echo=0');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
echo $select;
?>
<noscript><div><input type="submit" value="View" /></div></noscript>
</div></form>

Sunday, July 22, 2012

How to execute shortcodes inside custom fields in wordpress

How to execute shortcodes inside custom fields in wordpress

WordPress by default do not allows shortcodes to be executed inside custom fields. If you want to display something with the help of shortcode inside a specific custom field, then you have to follow the simple steps

Put the following code into whatever page where you are displaying the results of the shortcode, and then change the my_wp_custom_field_here to the name of your own custom field.

<?php echo apply_filters('the_content', get_post_meta($post->ID, 'my_wp_custom_field_here', true)); ?>

Saturday, June 16, 2012

How to Remove the Width and Height Attributes From WP Image Uploader

How to Remove the Width and Height Attributes From WP Image Uploader


When we upload images in WordPress using image uploader and insert that image into wordpress posts, WordPress always automatically include the image width and height attributes in the html <img> tag. But sometimes that can give us some problem, because that may not fit in our layout . So using the following code we can get rid of those height and width attributes.

Just paste the following code into  functions.php file under theme folder.

add_filter( 'post_thumbnail_html', 'remove_width_attribute', 10 );
add_filter( 'image_send_to_editor', 'remove_width_attribute', 10 );

function remove_width_attribute( $html ) {
   $html = preg_replace( '/(width|height)="\d*"\s/', "", $html );
   return $html;
}

Tuesday, June 5, 2012

How to display RSS feeds on WordPress

How to display RSS feeds on WordPress

If you ever want to display any rss feed on your WordPress blog then follow the process. The simple code that will do the job without using the deprecated wp_rss() function in wordpress.


The following code you have to paste in template pages wherever you wanna display the rss feed.
Please  update the feed url on line 3. and the Number of items you want to display can be defined on line 6.

<?php
include_once(ABSPATH . WPINC . '/rss.php');
$feed = 'http://sandipdas.in/feed';
$rss = fetch_feed($feed);
if (!is_wp_error( $rss ) ) :
    $maxitems = $rss->get_item_quantity(3);
    $rss_items = $rss->get_items(0, $maxitems);
    if ($rss_items):
        echo "<ul>\n";
        foreach ( $rss_items as $item ) :
            echo '<li>';
            echo '<a href="' . $item->get_permalink() . '">' . $item->get_title() . "</a>\n";
            echo '<p>' . $item->get_description() . "</li>\n";
        endforeach;
        echo "</ul>\n";
    endif;
endif;
?>

Friday, May 18, 2012

How to automatically create meta description from content in wordpress

How to automatically create meta description from content in wordpress


WordPress by default don't add a "meta description" tag to into blog. Its not necessary, but some SEO experts insists that this tag is important for our website SEO purpose. So isn't it a great idea about generating a "meta description" using the post content? In below I have describe a useful code which can do this purpose easily.
For this please paste the following code into the functions.php file under theme folder

function create_meta_desc() {
global $post;
if (!is_single()) { return; }
$meta = strip_tags($post->post_content);
$meta = strip_shortcodes($post->post_content);
$meta = str_replace(array("\n", "\r", "\t"), ' ', $meta);
$meta = substr($meta, 0, 125);
echo "< meta name='description' content='$meta' />";
}
add_action('wp_head', 'create_meta_desc');
The code is ready now

Tuesday, May 8, 2012

How to disable plugin updates on WordPress


How to disable plugin updates on your WordPress blog

Wordpress By default automatically checks if the plugins updates are available so after checking if its find new update available it will ask you to install it. Plugin update is useful in most cases, but when you may not want them to updates plugins, like if you modified a plugin especially for perticular website. So I describe an easy way to disable plugin updates on any WordPress blog, Please check

So simple: Just paste the following code into functions.php and save it. Thats all

remove_action( 'load-update-core.php', 'wp_update_plugins' );
add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "return null;" ) );

Thursday, April 5, 2012

Prevent WordPress to compress your jpg images

Prevent WordPress to compress your jpg images

Here I describe how you Prevent WordPress to compress your jpg images because by default, WordPress compress your uploaded jpg images

To do this just Open functions.php file from your theme folder and paste the following code below in the functions.php file:

add_filter('jpeg_quality', function($arg){return 100;});

Now Save the file.

 

Saturday, March 10, 2012

Replace excerpt ellipsis with post permalink

This is very useful tricks to replace the ellipsis [...] from the excerpt with a permalink to the post in wordpress.

Just paste the code below into your functions.php file in theme folder of wordpress. After saved, this tip will be applied to the wordpress blog.



function replace_excerpt($content) {
       return str_replace('[...]',
               '... <div class="more-link"><a href="'. get_permalink() .'">Continue Reading</a></div>',
               $content
       );
}
add_filter('the_excerpt', 'replace_excerpt');

Tuesday, March 6, 2012

Embed a page into another page in Wordpress

Embed a page into another page in Wordpress

Just paste the following code within the loop and make sure that you update page ID on line 1!


<?php $recent = new WP_Query("page_id=**ID**"); while($recent->have_posts()) : $recent->the_post();?>
       <h3><?php the_title(); ?></h3>
       <?php the_content(); ?>
<?php endwhile; ?>

Sunday, February 19, 2012

Add a login form on WordPress Theme

Add a login form on WordPress Theme

To display a login form just paste the following code on where you will like to display the wordpress login form. Like in sidebar or ant page template


<?php if (!(current_user_can('level_0'))){ ?>
<h2>Login Here</h2>
<form action="<?php echo get_option('home'); ?>/wp-login.php" method="post">
<input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="20" />
<input type="password" name="pwd" id="pwd" size="20" />
<input type="submit" name="submit" value="Send" class="button" />
    <p>
       <label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label>
       <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
    </p>
</form>
<a href="<?php echo get_option('home'); ?>/wp-login.php?action=lostpassword">Recover password</a>
<?php } else { ?>
<h2>Logout</h2>
<a href="<?php echo wp_logout_url(urlencode($_SERVER['REQUEST_URI'])); ?>">logout</a><br />
<a href="http://sandipdas.in/wp-admin/">admin</a>
<?php }?>

Saturday, February 18, 2012

Create thumbnail images using PHP

How to Create thumbnail images using PHP

By the following code you can understand how to create a thumbnail of a image

To create a thumbnail, we read in the file using the imagecreatefromjpeg() function and calculate the new thumbnail size. imagesx() and imagesy() functions return the width and height of the image respectively. Then we create a new image using the imagecreatetruecolor(). and Finally, we copy and resize the original file with the imagecopyresized() function and save thumbnail with imagejpeg()


$thumbWidth=70; // fix your widht
$image="mm_travel_photo1.jpg";
$src_img=imagecreatefromjpeg($image);
// get old widht and height
$old_w=imagesx($src_img);
$old_h=imagesy($src_img);
// calculate new widht and height;
$new_width = $thumbWidth;
$new_height = floor( $old_h * ( $thumbWidth / $old_w ) );
$tmp_image=imagecreatetruecolor($new_width,$new_height); // craete tmp images
imagecopyresampled( $tmp_image,$src_img, 0, 0, 0, 0, $new_width, $new_height, $old_w, $old_h);
imagejpeg( $tmp_image, "abc.jpeg" ); // get  the image and name it as abc.jpeg
imagedestroy( $tmp_image );


This process  can support for png and gif also

Extra contact methods to user profiles in wordpress

How to Add extra contact methods to user profiles in Wordpress

The following simple way you can do this , For this Paste the following code into function.php fille and then edit the line 4 and 5 as require.

add_filter('user_othercontactmethods', 'my_user_othercontactmethods');

function my_user_othercontactmethods($user_othercontactmethods){
  $user_othercontactmethods['facebook'] = 'Facebook Username';
  $user_othercontactmethods['twitter'] = 'Twitter Username';

  return $user_othercontactmethods;
}



Monday, January 16, 2012

Display custom text in wordpress

Display custom text in wordpress

Using modified the_excerpt() function we can display an excerpt which is not longer than a predetermined length and doesn’t cut off in mid-sentence.

To do is open functions.php file and paste the code below in it which works as a function

// Variable & intelligent excerpt length.
function print_excerpt($length) { // Max excerpt length. Length is set in characters
    global $post;
    $text = $post->post_excerpt;
    if ( '' == $text ) {
        $text = get_the_content('');
        $text = apply_filters('the_content', $text);
        $text = str_replace(']]>', ']]>', $text);
    }
    $text = strip_shortcodes($text); // optional, recommended
    $text = strip_tags($text); // use ' $text = strip_tags($text,'< p >< a >'); ' if you want to keep some tags

    $text = substr($text,0,$length);
    $excerpt = reverse_strrchr($text, '.', 1);
    if( $excerpt ) {
        echo apply_filters('the_excerpt',$excerpt);
    } else {
        echo apply_filters('the_excerpt',$text);
    }
}

// Returns the portion of haystack which goes until the last occurrence of needle
function reverse_strrchr($haystack, $needle, $trail) {
    return strrpos($haystack, $needle) ? substr($haystack, 0, strrpos($haystack, $needle) + $trail) : false;
}



Now you can use the print_excerpt() function in the theme files like this:

 print_excerpt(50);

I just got my #domain @BigRock. Get upto 25% off with my personalized coupon link Get upto 25% off