Some very useful wordpress hacks

Today i organize some very useful WordPress hacks.Hope this may help you in your future projects

Display number of Facebook fans in full text

If you want to display the number of your Facebook Fans then use this code.

Replace “YOUR PAGE-ID” with your own Page-ID.

Code:

$page_id = "YOUR PAGE-ID"; $xml = @simplexml_load_file("http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=".$page_id."") or die ("a lot"); $fans = $xml--->page->fan_count;
echo $fans;

Source: http://wp-snippets.com/742/display-number-facebook-fans/

Display search terms from Google users

If a visitor reached your site through Google’s search, this script will display the terms they searched for in order to find your site. Put this code where you want to display the message.

$refer = $_SERVER["HTTP_REFERER"];
if (strpos($refer, "google")) {
	$refer_string = parse_url($refer, PHP_URL_QUERY);
	parse_str($refer_string, $vars);
	$search_terms = $vars['q'];
	echo 'Welcome Google visitor! You searched for the following terms to get here: ';
	echo $search_terms;
};

Source: http://wp-snippets.com/820/display-search-terms-from-google-users/

How to automatically email contributors when their posts are published

If you’re running a multi-authored blog, it can be very cool to let your contributors know when their post are online. Today’s recipe will show you how to do this automatically each time a post is published.

function wpr_authorNotification($post_id) { $post = get_post($post_id); $author = get_userdata($post->post_author); $message = " Hi ".$author->display_name.", Your post, ".$post->post_title." has just been published. Well done! "; wp_mail($author->user_email, "Your article is online", $message); } add_action('publish_post', 'wpr_authorNotification');

Source: http://www.binarymoon.co.uk/2010/02/automated-take-screenshots-website-free/

How to define a minimum word count per post

If you want to be able to keep a minimum word count for your posts, then just read this recipe. Applying it to your blog can be useful to maintain a clean layout, or ensure your guest writers will not post too short articles on your blog.

function minWord($content){ global $post; $num = 100; //set this to the minimum number of words $content = $post->post_content; if (str_word_count($content) < $num) wp_die( __('Error: your post is below the minimum word count.') ); } add_action('publish_post', 'minWord');

Source: http://pippinspages.com/tutorials/minimum-word-count-for-wordpress-posts/

Automatically add a Google+ button to your posts

This simple piece of code to automatically add a Google+ button to your posts.

Open your functions.php file and paste the following code in it:

add_filter('the_content', 'wpr_google_plusone'); function wpr_google_plusone($content) { $content = $content.'<div><g:plusone size="tall" href="'.get_permalink().'"></g:plusone></div>'; return $content; } add_action ('wp_enqueue_scripts','wpr_google_plusone_script'); function wpr_google_plusone_script() { wp_enqueue_script('google-plusone', 'https://apis.google.com/js/plusone.js', array(), null); }

Source: http://spyrestudios.com/17-time-saving-code-snippets-for-wordpress-developers/

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply