Show related posts with wordpress post without plugin

For reducing bounce rate Show related posts with wordpress post without plugin is really great solution. There are many wordpress plugins which will give similar functionality but it will add extra code server hits to your server. It causes slowness.

Show related posts with wordpress post

Just copy paste the following code in your functions.php file.  You will find this file in your wordpress theme folder.

Show related posts with wordpress post
Show related posts with wordpress post
function get_related_posts($post_id) {
$tags = wp_get_post_tags($post_id);
if ($tags) {
echo 'Check some Related Posts<br>';
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
'showposts'=>10,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
$the_permalink = get_permalink();
$post_title =  get_the_title();
$related_post = '<a href="'.$the_permalink.'">'.$post_title.'</a><br>';
echo $related_post;
endwhile;
}
}
}

You just need to use this function in your loop using “get_related_posts();” this function.

add common content after every wordpress post

WordPress tutorial, In this article we will show, how to add common content after every wordpress post. We given simple code for adding in wordpress theme.

Just copy paste the following code in your functions.php file.  You will find this file in your wordpress theme folder.

add common content after every wordpress post


function insert_common_content($_common_content) {
if(!is_feed() && !is_home()) {
$_common_content.= "<div class='wordpressapi'>";
$_common_content.= "<h4>Enjoyed this article?</h4>";
$_common_content.= "Check more articles on <a href='http://images.purabtech.in/'>purabtech.in/files/</a>";
$_common_content.= "</div>";
}
return $_common_content;
}
add_filter ('the_content', 'insert_common_content');

add common content after every wordpress post
add common content after every wordpress post

Useful article related to this wordpress hack.

http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content

wordpress check if post has image attachment

In custom theme checking post image is really useful because old post has no featured image set. Using our code wordpress check if post has image attachment. Just use following code the check for image in wordpress post.

wordpress check if post has image attachment

Copy paste the following function in functions.php file.


function check_image(){
$content = $post->post_content;
$all_images = '~<img [^>]* />~';

preg_match_all( $all_images, $content, $pics );

// Check to see if we have at least 1 image
$all_pics = count($pics[0]);

if ( $all_pics > 0 ) {
// Your post have one or more images.
return true
} else {
return false;

}

wordpress check if post has image attachment
wordpress check if post has image attachment

In post loop just add or call this function. This function will return the true or false.

get first image thumbnail from wordpress post

Most WordPress theme are using custom fields to display thumbs on their blog homepage. How to get first image thumbnail from wordpress post

get first image thumbnail from wordpress post

But you can take easily extract the first image from the post, and display the image as post thumbnail.

Just copy paste the following function in your functions.php file.


function get_first_image($id) {
$PostID = $id;
$all_images =& get_children('post_type=attachment&post_mime_type=image&post_parent=' . $PostID );

if($all_images) {

$arr_of_all_images = array_keys($all_images);

// Get the first image attachment from post
$firstImage = $arr_of_all_images[0];

// Get the thumbnail url for the attachment
// If you want the full-size image instead of the thumbnail, use wp_get_attachment_url() instead of wp_get_attachment_thumb_url().
$thumb_url = wp_get_attachment_thumb_url($firstImage);

// Build the <img> string
$First_thumb_image = '<a href="' . get_permalink() . '">' .
'src="' . $thumb_url . '" width="150" height="150" alt="Thumbnail Image" title="Thumbnail Image" />' .
'</a>';

// Print the thum image form post
echo $First_thumb_image;
}
}

You can call above “get_first_image” function anywhere in your post loop. I loop you need to just copy paste the following lines
to print the first image of post body.

<!--?php get_first_image($post--->ID);  ?>
get first image thumbnail from wordpress post
get first image thumbnail from wordpress post

Follwing article I found useful

http://codex.wordpress.org/Plugin_API/Filter_Reference

http://codex.wordpress.org/Function_Reference/wp_get_attachment_thumb_url

Put Google Analytics code into your wordpress theme

Adding Google Analytics is important for website. Here in this article we given code snippet and show to Put Google Analytics code into your wordpress theme

Put Google Analytics code into your wordpress theme

Copy paste following lines to your wordpress theme folder’s functions.php file.


function google_analytics() {

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-12453889-1");
pageTracker._trackPageview();
} catch(err) {}</script>
}
add_action('wp_footer', 'google_analytics');

Dont forget to replace your google analytics code in google_analytics code.

Put Google Analytics code into your wordpress theme
Put Google Analytics code into your wordpress theme

have fun!

Change WordPress login logo using wordpress hack

If you want to Change WordPress login logo using wordpress hack. Just copy paste following lines to your wordpress theme folder’s functions.php file for this. There is very small code snippet you need put in your wordpress theme.

Change WordPress login logo using wordpress hack

function change_login_logo() {
echo ‘<style type=”text/css”>
h1 a { background-image:url(‘.get_bloginfo(‘template_directory’).’/images/logo.png); }
</style>’;
}

add_action(‘login_head’, ‘change_login_logo’);

Change WordPress login logo using wordpress hack
Change WordPress login logo using wordpress hack

have fun!

how to add favicon to wordpress theme

Favion is small image icon which is shown on browser left top side. Left side of browser address bar, we can see the favicon image. Here in this article We will show you, how to add add favicon to wordpress theme.

how to add favicon to wordpress theme

Create favicon image using photoshop or any photo editing tool. Favicon image side should be 16x16px or 32x32px. Many times favicon image should be .ico or png format. All latest browser are able to show png format image but in old browser icon format image should be supported.

Just copy paste the following lines to your function.php file.

<?php 
function add_favicon() {
?>
<link rel="shortcut icon" href="<?php echo bloginfo('stylesheet_directory') ?>/images/favicon.ico" >
<?php 
}
add_action('wp_head', 'add_favicon');
?>

if wp_head() function added in your header.php file, If that function not added then this hack will never work

Or you can just add favicon image file in themes folder and use following code in header.php file.


<link rel="icon" href="https://purabtech.in/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="https://purabtech.in/favicon.ico" type="image/x-icon" />

how to add favicon to wordpress theme
how to add favicon to wordpress theme

How to add social media buttons to wordpress sidebar

First you need to download social icons. Make sure icons are free. add social media buttons to wordpress sidebar Using simple HTML code, given by us. You just need copy and paste following code in to your sidebar text wordpress widget.

How to add social media buttons to wordpress sidebar

I created following steps to add the icons to wordpress site for non developers.

1. Upload the icon image(s) to your media library.

How to add social media buttons to wordpress sidebar
How to add social media buttons to wordpress sidebar

2. Add a “Text” widget to your sidebar and insert code similar to the following:


<a href="http://twitter.com/wordpressapi"><img src="http://images.purabtech.in/twitter_48x48.png" alt="" /></a><a href="facebook.com/wordpressapi"><img src="http://images.purabtech.in/facebook_48x48.png" alt="" /> </a>
<a href="mailto:support@purabtech.in/files/"><img src="http://www.wordpress.com/wp-content/uploads/email_48x48.png" /></a> 
<a href="http://images.purabtech.in/feed/"><img src="http://images.purabtech.in/rss_48x48.png" /></a> 
 

Then just change the URLs so that they point to your icons and links. As you can see,

I have four icons in my sidebar (twitter, facebook, email, and rss).

Tricks for improving WordPress site performance

WordPress, by default, comes uncompressed and sends the uncompressed HTML to the visitor’s browser. we given some Tricks for improving WordPress site performance.

Please use this tricks carefuly because First trick will cause issue to your wordpress site.

First Trick
Improve the  wordpress Blog’s Loading Speed

Tricks for improving WordPress site performance

Create one file called “phpinfo.php” and then upload it to the root of your blog directory:

In phpinfo.php fine copy paste following code.


<?php phpinfo(); ?>

Check on server zlib is enabled or not.

Copy paste the following code in to your header.php file above the Doctype tag.


<?php
ini_set('zlib.output_compression', 'On');
ini_set('zlib.output_compression_level', '1');
?>

This trick will improve your speed upto 50%.

Code taken from following link :
http://www.wprecipes.com/compress-wordpress-output-and-speed-your-blogs-load-speed

Tricks for improving WordPress site performance
Tricks for improving WordPress site performance

Second Trick

Allow More Time For Slow Servers to Upgrade WordPress

Open the wp-admin/includes/files.php file and go to line 448.

For WordPressMU users path is wp-admin/includes/file.php and line no 450.

Find this line

$response = wp_remote_get($url, array('timeout' => 60));

replace with

$response = wp_remote_get($url, array('timeout' => 120));

This will change the server response time to 120 second.

Code taken from following link :
http://www.wprecipes.com/wordpress-upgrade-allow-more-time-for-slow-servers

1000 free social networking vector icons

I found very useful links to find and download the social networking icons. In every website we required the social icons and vector images for using the site. I collected some we nice collection of social icons links.

1000 free social networking vector icons

There are indeed free high-quality icon sets. Through icons we can check the web designers and graphic artist’s skill.

1000 free social networking vector icons
1000 free social networking vector icons

http://www.thedesigncubicle.com/2009/04/600-free-design-twitter-and-social-media-icons-a-collection-motherload/

http://sherifabdou.com/2009/03/60-free-vectors-icons-for-web-designers/

http://www.blogreign.com/2009/06/16-sets-amazing-social-networking-icons-free-download/

http://webtreats.mysitemyway.com/154-free-glassy-space-social-networking-icons/

http://sherifabdou.com/2009/03/60-free-vectors-icons-for-web-designers/

http://digg.com/design/Free_Social_Network_Icons

http://designreviver.com/freebies/6-free-new-social-icons-digg-twitter-stumble-rss-delicious-reddit/

http://www.komodomedia.com/blog/2009/06/social-network-icon-pack/

http://www.smashingmagazine.com/2008/03/06/35-really-incredible-free-icon-sets/

I searched for facebook, twitter, feedburner, digg.