Menu

15 Useful WordPress Hacks

WordPress website owners, especially the inexperienced ones, use different WordPress plugins to increase their site’s features and functionalities with an intention to fulfill the growing demands of users.

However, using too many plugins can make your site slow and clunky. You could face several problems when you fail to adopt a series of new updates (of plugins) on your site. If you have a little knowledge of PHP skills (such as the elementary knowledge of web applications/services, Linux, Apache, FOSS tools and technologies, OOPS concepts, understanding of frameworks and architecture pattern, database concepts, client-side scripting, etc,) and are ready to perform small changes in your WordPress site yourself, then you can use WordPress hacks.

With WordPress hacks, you can easily manage the different functionalities of your site easily and boost its performance. So, have a look at this list of some quality WordPress hacks detailed below:

1. To Prevent Search Engines From Indexing Your Web Pages

Website creation takes a significant amount of time. Whenever new sites go online, search engine bots visit them for indexing. While creating websites or its pages, you would never want incomplete websites or pages to be indexed by search engines. It would create a bad impression in the mind of users (about your brand) and search engines may downgrade its ranking later on.

Apart from this, many webmasters want to stop the indexing of the admin area of their sites to protect it from hackers.

Therefore, if you want to stop search engines to from indexing your web pages or its certain parts, just add this script in the <head> section of your header.php file.

Source code      
<?php if(is_search()) { ?>
 <meta name=”robots” content=”noindex, nofollow” />
<?php }?>  

2. To Disable Login Hints For WordPress Sites

WordPress websites are frequently targeted by hackers and cyber criminals. So, keeping your website safe from various online security threats and attempts always seem like a challenging job.

You can do this easily by not displaying the detailed error messages on your site’s login page. To do so, open the functions.php file of your site and paste the following-

function no_wordpress_errors(){
 return ‘GET OFF MY LAWN !! RIGHT NOW !!’;
}
add_filter( ‘login_errors’, ‘no_wordpress_errors’ );

3. To Add a Shortcode to WordPress Widget

Shortcodes replace long codes and allow you to perform complex things using minimum codes. They empower you to add numerous functionalities to your content and make them more interesting.

Nevertheless, WordPress widgets treat shortcodes as regular text by default. You can change this situation by using the following code in the functions.php file-

 add_filter(‘widget_text’, ‘do_shortcode’);

 4. To Schedule Future Post

For a number of reasons, WordPress bloggers like to schedule their upcoming posts in advance so that they may get their articles published automatically at the right time. Family and social responsibilities, traveling, 9 to 5 jobs, visitors from different time zones, etc, compel you to use the content scheduling option.

In order to schedule your upcoming post on your site, open your sidebar.php and add the following code-

1<?php query_posts(‘showposts=10&post_status=future’); ?>
2
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
3
<h2><?php the_title(); ?></h2>
4
<span class=”datetime”><?php the_time(‘j. F Y’); ?></span></p>
5
<?php endwhile;
6
else: ?><p>No future events scheduled.</p>
7
<?php endif; ?>

5. To Display RSS Feeds

If you display RSS feed on your site, it benefits you greatly in terms of website traffic, ranking in search engine results and allows visitors to access new content easily. To display RSS feeds on your site, open the sidebar.php and write the following code-

1
<?php include_once(ABSPATH.WPINC.’/rss.php’);
2
wp_rss(‘http://feeds2.feedburner.com/wpbeginner’, 5); ?>

After this, just save the file.

6. To Display The Most Popular Posts

If you actively browse different websites on the web, you would have seen sites with “most popular articles” section. The admin of such websites do so with a clear intention to get more pages views, increase their interaction with readers and reduce the bounce rate of their sites. So, if you also want to display popular posts for your readers, you should place a code in your theme files. For example- if you want to display popular posts in sidebar section, just open up the sidebar.php and write the following code:

1
<h2>Popular Posts</h2>
2
 <ul>
3
 <?php $result = $wpdb->get_results(“SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5”);
4
 foreach ($result as $post) {
5
 setup_postdata($post);
6
 $postid = $post->ID;
7
 $title = $post->post_title;
8
 $commentcount = $post->comment_count;
9
 if ($commentcount != 0) { ?>
10
 
11
<li><a href=”<?php echo get_permalink($postid); ?>” title=”<?php echo $title ?>”>
12
 <?php echo $title ?></a> {<?php echo $commentcount ?>}</li>
13
 <?php } } ?>
14
 
15
</ul>

7. To Display The Related Posts

Every website owners want visitors to stay longer on his/her site and read more content. You can do that easily by displaying the similar posts. They encourage visitors to read another content once they go through one content.

To display the related post on your WordPress site, you should open the single.php file in your theme and paste the below- mentioned code. The code will showcase the related post on the basis of the current post which is being visited by the users.

1
<?php
2
//for use in the loop, list 5 post titles related to first tag on current post
3
$tags = wp_get_post_tags($post->ID);  
4
if ($tags) {  
5
 echo ‘Related Posts’;  
6
 $first_tag = $tags[0]->term_id;  
7
 $args=array(  
8
 ‘tag__in’ => array($first_tag),  
9
 ‘post__not_in’ => array($post->ID),  
10
 ‘showposts’=>5,  ‘caller_get_posts’=>1
11
 );  
12
 $my_query = new WP_Query($args);  
13
 if( $my_query->have_posts() ) {  
14
 while ($my_query->have_posts()) : $my_query->the_post(); ?>  
15
  <p><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a></p>  
16
 <?php endwhile;  
17
 }  
18
}

8. To Add a Print Button to Your WordPress Posts

While operating your site, you hardly need to get your web pages printed. But, if you think from user’s viewpoint, the situation looks completely different. There are many visitors that find your content interesting and they want to print your live content for their own presentation.

Therefore, it’s always beneficial to allow visitors to print your blog posts. Tech-savvy people can easily print site’s content using keyboard shortcuts or browser settings. But, you can’t expect all to perform this action from all people especially old persons, students, etc.

To add the print option to posts, open your single.php file from theme folder and add the below- mentioned codes-

1
<a href=”javascript:window.print()” rel=”nofollow”>Print this Article</a>

9. To Create “Share on Facebook” Button

Facebook is popular social media channel with a large user base. Its users are rapidly increasing with each passing day. When you share your web pages on Facebook, it helps you to increase traffic to your site and explore more business opportunities.

So, to add a “Share on Facebook” link to your website, open up the single.php file in your theme and paste the following code in the loop:

1
<a href=”http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>&t=<?php the_title(); ?>” target=”blank”>Share on Facebook</a>

Alternatively, you can use the getTinyUrl() function-

1
<?php $turl = getTinyUrl(get_permalink($post->ID)); ?>
2
<a href=”http://www.facebook.com/sharer.php?u=<?php echo $turl;?>&t=<?php the_title(); ?>” target=”blank”>Share on Facebook</a>  

10. To Add Author Information to all Posts

By displaying author bio beneath every post you can increase its credibility. It also helps authors to make their name on the World Wide Web by writing valuable & useful articles for the targeted audience.

In every user profile, you can place information about yourself and co-authors (in case you run a multi-author site or blog).

Just open Stylesheet and add the following:

1
.postauthor {  
2
}

After completing this step, open up “index.php” file in theme and find the following:

1
<?php the_content(‘Read the rest of this entry »’); ?>

Add the following in above-mentioned function

1
<div class=”postauthor “>
2
 <?php the_author_description(); ? >
3
</div>

Once, you complete this step, it will start displaying author bio in place.

11. Break Long Posts into Small Ones

Website owners always look for ways to make content more interesting for visitors and improve their reading experience. When you publish long posts on your site, many visitors consider them boring and they don’t go through it completely.

You can easily break long WordPress posts into several pages and allow readers to go through them without any problem. Just pick the point you want to split your posts and add the following code-

<!––nextpage––>

WordPress will split the page and rest of the post will start appearing on next pages.

12. To Close Comments on Old Articles

While running a website, sometimes you notice an unprecedented surge in spam comments on old posts. Spammers flood your site comment section with needless comments, links to harmful sites, etc, to damage your site.

You can disable the comment option on old posts. To do so, just go to Settings » Discussion page »‘Other comment settings’ section, set the number of days and save the changes you have made.

13. To Change The Number of Displayed Posts

WordPress displays 10 posts on your blog pages and achieves. Depending upon your needs, you can easily change the default setting.

To do so, go to visit Settings » Reading page and look for ‘Blog pages show at most’ option. Set the number of posts you want to display and save changes you made.

14. Disable Comments Notification Emails in WordPress

Whenever someone comments on your website or any comment are under moderation stage, WordPress automatically sends you Email notifications about that. It is very useful when your website is new and you want to interact with visitors to boost its readability and usability.

Once, you start to get lots of traffic on your site, comment notifications becomes a problem for you. Your Email inbox is flooded with numerous notifications, making it impossible for you reply all of them.

Fortunately, you can disable those notifications easily. Just navigate to your site’s admin area» the Settings » Discussion page and find ‘Email Me Whenever’ section. Uncheck both options under that setting and save the changes.

15. To Xxclude Categories From RSS Feeds

There is no meaning of displaying categories in RSS feeds as most of the visitors just require the content. They have nothing to do with the categories. If you want to exclude categories from your RSS feeds, then follow the below-mentioned steps:

To exclude categories from RSS feeds, you need to know their numeric ID. In case, you don’t know that just sign in your WordPress dashboard and go to the categories section. Now, place the mouse cursor on the “edit “ link related to the categories you want to find the ID and see the numeric value for that in browser’s status bar.

As soon as you get the ID of that categories (which you want to exclude), just open the “function.php” file, paste the following code and save the changes. In case, your theme doesn’t have “function.php” file, then you need to create it.

1
function myFilter($query) {
2
 if ($query->is_feed) {
3
 $query->set(‘cat’,’-5′); //Don’t forget to change the category ID =^o^=
4
 }
5
 return $query;
6
}
7
 
8
add_filter(‘pre_get_posts’,’myFilter’);

Final Words

These are some useful WordPress hacks. Using these hacks, you can perform important functions of WordPress easily and can operate it successfully even without using too many plugins.

Leave a Reply

Your email address will not be published. Required fields are marked *