After most of the Graphics based compilations, we decided to articles our second series of Most Wanted WordPress Hacks. The First Article of this series was posted Earlier , you can read the Article “10 Most-Wanted WordPress Hacks for Better Productivity”. We have continued the series with this Article , and this article corresponds to the most wanted hacks for WordPress.
Note that these Hacks are not made according to an Individual”s Purpose, you are free to change to get your desirable results.If you are searching for the hack which is”nt here, then you can ask us in the comments section. We will try our best to solve your problem as fast as possible.
Set a Maximum Word Count on Post Titles
Simply paste this in functions.php file.
function maxWord($title){
global $post;$title = $post->post_title;
if (str_word_count($title) >= 10 )
//set this to the maximum number of words
wp_die( __('Error: your post title is over the maximum word count.') );
}
add_action('publish_post', 'maxWord');
Count Retweets in Full Text
Paste this in functions.php file.
function tweetCount($url) {
$content = file_get_contents("http://api.tweetmeme.com/url_info?url=".$url);
$element = new SimpleXmlElement($content);
$retweets = $element->story->url_count;
if($retweets){return $retweets;}
else {return 0;}
}
Once done, paste this in single.php
$rt = tweetCount(get_permalink());echo "Retweeted ".$rt." times.";
Upgrades using FTP
First backup your wp-config.php and then add below code in wp-config.php and then save it.
define('FTP_HOST', 'ftp.yoursite.com');
define('FTP_USER', 'Your_FTP_Username');
define('FTP_PASS', 'Your_FTP_password');
define('FTP_SSL', true);
Notify your Members on New Posts
Just paste the following code on your functions.php file. After saving the file, all registered users will be Informed of New Post.
function email_members($post_ID) {
global $wpdb;$usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;");
$users = implode(",", $usersarray);
mail($users, "New WordPress recipe online!", 'A new recipe have been published');
return $post_ID;
}
add_action('publish_post', 'email_members');
Define a Minimum Word Count Per Post
Copy the function below and paste it into your functions.php file.
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');
Get Rid of HTML in Comments
Paste the function in your theme’s functions.php.
// This will occur when the comment is posted
function plc_comment_post( $incoming_comment ) {
// convert everything in a comment to display literally
$incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);
// the one exception is single quotes, which cannot be #039; because WordPress marks it as spam
$incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] );
return( $incoming_comment );}
// This will occur before a comment is displayed
function plc_comment_display( $comment_to_display ) {
// Put the single quotes back in$comment_to_display = str_replace( ''', "'", $comment_to_display );
return $comment_to_display;}add_filter( 'preprocess_comment', 'plc_comment_post', '', 1);
add_filter( 'comment_text', 'plc_comment_display', '', 1);
add_filter( 'comment_text_rss', 'plc_comment_display', '', 1);
add_filter( 'comment_excerpt', 'plc_comment_display', '', 1);
Display Time as “Time Ago”
Just Paste this wherever you want to display between the loop.
Posted <?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago'; ?>
Remove Admin name in Comments Class
Simple paste this in functions.php
function remove_comment_author_class( $classes ) {foreach( $classes as $key => $class ) {if(strstr($class, "comment-author-")) {unset( $classes[$key] );}}return $classes;}add_filter( 'comment_class' , 'remove_comment_author_class' );
Display Thumbnail in RSS Feed
Simply paste the following code in your functions.php file.
function diw_post_thumbnail_feeds($content) {
global $post;if(has_post_thumbnail($post->ID)) {
$content = '<div>' . get_the_post_thumbnail($post->ID) . '</div>' . $content;
}return $content;
}
add_filter('the_excerpt_rss', 'diw_post_thumbnail_feeds');
add_filter('the_content_feed', 'diw_post_thumbnail_feeds');
Add Print Button To Your Posts
Paste the below code wherever you want in the loop.
<a href="javascript:window.print()">Print this Article</a>
List Your Scheduled Posts
Paste the code where you want to show scheduled posts.
<?php$my_query = new WP_Query('post_status=future&order=DESC&showposts=5');
if ($my_query->have_posts()) {while ($my_query->have_posts()) : $my_query->the_post();?>
<li><?php the_title(); ?></li><?php endwhile;}?>
Protect wp-config File
Paste this in your .htaccess file.
<files wp-config.php>order allow,denydeny from all</files>
Add Favicon To Your Blog
Paste this in your theme”s functions.php file.
function childtheme_favicon() {
?><link rel="shortcut icon" href="<?php echo bloginfo('stylesheet_directory') ?>/images/favicon.png" ><?php }
add_action('wp_head', 'childtheme_favicon');
Change The Default “Admin” Username
Simply run this SQL query once. Also don”nt forget to put your new Username.
UPDATE wp_users SET user_login = 'Your New Username' WHERE user_login = 'Admin';
Change the Default Gravatar Button
Paste this in functions.php file of your theme.
function newgravatar ($avatar_defaults) {
$myavatar = get_bloginfo('template_directory') . '/images/gravataricon.gif';
$avatar_defaults[$myavatar] = "SmashinGeeks"
return $avatar_defaults;
}
add_filter( 'avatar_defaults', 'newgravatar' );
Display Certain Categories in a Menu
Paste the below code in the menu section of your blog.
<ul style="float:left; width:730px;"><?php wp_list_categories('orderby=name&include=7,9,19,16,1,5,17,23'); ?></ul>
Display Latest Sticky Posts
Paste the code where you want to display the latest sticky post.
<?php /* Get all sticky posts */ $sticky = get_option( 'sticky_posts' ); /* Sort the stickies with the newest ones at the top */ rsort( $sticky ); /* Get the 5 newest stickies (change 5 for a different number) */ $sticky = array_slice( $sticky, 0, 5 ); /* Query sticky posts */ query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );?>
Modify Excerpt Length and More Tags
Paste this code in functions.php file after changing the values according to you.
// Changing excerpt lengthfunction new_excerpt_length($length) {return 100;}add_filter('excerpt_length', 'new_excerpt_length');// Changing excerpt morefunction new_excerpt_more($more) {return '…';}add_filter('excerpt_more', 'new_excerpt_more');
Display Author’s Twitter and Facebook Info
Paste this in functions.php file.
<?phpfunction my_new_contactmethods( $contactmethods ) {// Add Twitter$contactmethods['twitter'] = 'Twitter';//add Facebook$contactmethods['facebook'] = 'Facebook';return $contactmethods;}add_filter('user_contactmethods','my_new_contactmethods',10,1);?>
Paste this where you want to display the Information.
<?php echo $curauth->twitter; ?>
Display Most Recent Tweet
Paste this where you want to display the Latest Tweet of yours. don”nt forget to place your Twitter Username in 1st line.
<?php
$username = "TwitterUsername"; // Your twitter username.$prefix = "";
// Prefix – some text you want displayed before your latest tweet.
$suffix = ""; // Suffix – some text you want display after your latest tweet.
$feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1";
function parse_feed($feed) {
$stepOne = explode("<content type=\"html\">", $feed);
$stepTwo = explode("</content>", $stepOne[1]);
$tweet = $stepTwo[0];
$tweet = str_replace("<", "<", $tweet);
$tweet = str_replace(">", ">", $tweet);
return $tweet;
}
$twitterFeed = file_get_contents($feed);echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);
?>
Print a post and few were too new for me dude:)
thanks for sharing this small hacks that make good difference to our blogs!
Very good collections listed out here, i love the 2nd and 4th actually. good job.. go ahead
very useful list of hacks
Thank You, They were really useful especially the user name changing one
Excellent list of all the wordpress hacks. Thanks for sharing this useful list.. I was searching for the wp-config security hack and visited your website.. thanks
We loved your website so much we added it to our sites to visit list at http://www.usbhubreview.net/sites-we-like Complete the FREE offer to make it permanent.
We loved your website so much we added it to our sites to visit list at http://www.usbhubreview.net/sites-we-like Complete the FREE offer to make it permanent.
Loved looking into this. Keep it up!
Really interesting post, I loved it!
I was seeking a post like this. Really refreshing take on the information. Thanks a lot.
I was looking for this. Really refreshing take on the information. Thanks a lot.
A very great post you made.
It’s actually a great and helpful piece of info. I’m glad that you just shared this helpful information with us. Please stay us informed like this. Thanks for sharing.