10 Easy To Follow WordPress Hacks For Developers

Developer hacks WordPress Hacks WordPress tips
|
January 27, 2020
10 Easy To Follow WordPress Hacks For Developers

WordPress currently tops the list of the three most often used website building packages globally. Exceptionally, it powers 35% of the Internet.

Wordpress Quote

One of the key aspects of its popularity is that it allows users to adapt in many ways. The site is flexible to meet the needs for blogging, e-commerce as an example. Simultaneously, it contains other benefits that are not limited to aspects such as:

  1. It is flexible and adaptable for different needs,
  2. It’s free,
  3. It’s  easy to customize with themes and plugins,
  4. It is SEO friendly,
  5. It’s safe and secure,
  6. It can handle different media types,
  7. The WordPress Community Offers Support.

The popularity of WordPress has resulted in the availability of a wide range of tips and tricks being accessible in order to take customizing one step further. Amazingly, it provides opportunities to update, change, edit or modify your content in the most convenient manner. Furthermore, if you want to unleash the true and full power of WordPress, let’s review the following hacks that will help you to do so.

It’s time to hack!

1. Delay Posts in RSS Feeds

Did it happen to you, that you have accidentally published an article before it was ready to go? Well, the majority of us have been there. Of course, you can simply unpublish the article and continue editing it.  

Unfortunately, email subscribers and RSS feed readers may have already received the article in their inbox. If you want to avoid this and delay posts from your RSS feed there is an easy fix. 

You can add the following code to the functions.php file of your theme or a site-specific plugin.

function publish_later_on_feed($where) {
 
    global $wpdb;
 
    if ( is_feed() ) {
        // timestamp in WP-format
        $now = gmdate('Y-m-d H:i:s');
 
        // value for wait; + device
        $wait = '10'; // integer 
        //http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
        $device = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
 
        // add SQL-sytax to default $where
        $where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
    }
    return $where;
} 
add_filter('posts_where', 'publish_later_on_feed');

This code helps to delay your published post from appearing in your RSS feed for 10 minutes.

2. Install Google Analytics in WordPress

Google Analytics should be one of the must-have tools in your WordPress site. It allows you to find out some important insights into your users’ behavior. An effective way to install it, especially if you don’t want to get troubled with coding is by using the MonsterInsights plugin.

3. Limit Login Attempts

By default, WordPress allows users to make an unlimited number of attempts to log in to a WordPress site. If this factor disturbs you, there’s an alternative to make the login attempts limited. You simply need to install and activate the Login LockDown plugin, which provides a limit on the amount of failed attempts a user can make to login.

4. Add Categories to WordPress Pages

By default, adding categories and tags are only available for posts in WordPress. Primarily because pages should be static standalone content. 

However, if you want to add tags and categories to various pages, then just add the following code to your theme’s functions.php file or a site-specific plugin.

// add tag and category support to pages
function tags_categories_support_all() {
  register_taxonomy_for_object_type('post_tag', 'page');
  register_taxonomy_for_object_type('category', 'page');  
}
 
// ensure all tags and categories are included in queries
function tags_categories_support_query($wp_query) {
  if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
  if ($wp_query->get('category_name')) $wp_query->set('post_type', 'any');
}
 
// tag and category hooks
add_action('init', 'tags_categories_support_all');
add_action('pre_get_posts', 'tags_categories_support_query');

5. Display Connected Posts Without Plugins

It’s an effective way to help your visitors stay longer on your website and get useful information when you provide them with related posts. However, not many developers know that there is an almost effortless way to assimilate this function by default. Below are the steps on how to do that:

  • Open the single.php file
  • Add the following code in the loop:
If ($tags) {
Echo ‘related posts’;
$first_tag = $tags[0]->term_id;
$args=array(
‘tag__in’ => array($post->ID),
‘showposts’=>5,
‘caller_get_posts’=>1
);
$my_query = new WP_Query($args);
If( $my_query->have posts() ) {
While ($my_query->have posts() : $my_query->the post(); ?>

6. Comments Subscription

Typically, users that leave a comment on your website have to revisit from time to time manually to be able to see the replies of their comments. In some cases, it could be more strategically effective to provide users with email notifications about new comments on their posts. 

Let’s find out how you can add this feature to your website. Yet again, it is as easy as installing and activating the Subscribe to Comments Reloaded plugin. After the activation, you have to visit Settings » Subscribe to Comments to put together the plugin settings.

7. Normal Quotes Usage

Did you know that WordPress turns normal quotes to smart codes? This has a risk of breaking your code snippet that you want to publish. You can avoid this by simply inserting the following code snippet to your functions.php file:

remove_filter (‘the_content’, ‘wptexturize’);

8.  Upsurge PHP Memory

While activating a large plugin, you might come across an error saying that the memory is exhausted. If you want to solve this problem by inserting the following line of code to your wp-config.php file.

define(‘WP_MEMORY_LIMIT’, ‘64M’);

This code will help to enhance the memory limit to 64M. Nonetheless, you can also modify this value to whatever amount your hosting server can upkeep.

9. Add Featured Image or Post Thumbnail to RSS Feed

As also mentioned in the upcoming tip, it’s good to know that WordPress RSS feeds show a list of your most recent articles. Take into consideration that in case you are showing full articles in the feed, the images inside the article will be displayed. However, it will eliminate and not show the featured image or post thumbnail in the article. 

If you want to change this try to add this code into your theme’s functions.php file or a site-specific plugin.

function rss_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<p>' . get_the_post_thumbnail($post->ID) .
'</p>' . get_the_content();
}
return $content;
}
add_filter('the_excerpt_rss', 'rss_post_thumbnail');
add_filter('the_content_feed', 'rss_post_thumbnail');

Additional tip from our Digilite Developers’ Team: 

10. Display Excerpt (Post Summary) on Home and Archive Pages

As experts in web development, we would recommend having short summaries of articles in your home and achieving pages, instead of the full text. This will help you to improve the load of the pages faster, gain more page views. Keep in mind to also refrain from having duplicate content across your website.

In order to do this follow the steps:

Open your index.php file, archive.php file, and category.php file. Note that some of you might not have all these files in your template. Simply open the ones that you do have.

Find the following code:

<?php the_content(); ?>

Replace it with:

<?php the_excerpt(); ?>

If you want to have more effective control over the output, our team of experienced developers recommends using this relevantly new function:

wp_trim_words( string $text, int $num_words = 55, string $more = null ); 

Now, you can freely custom excerpts for your posts from your WordPress admin panel and then display it your theme.

Note that in case you do not write a custom excerpt WordPress will automatically take the first 55 words of your article, put it in an excerpt with ellipses, and display it. If you want to change the word limit you have to start from WordPress 2.9. For doing that open your functions.php file and add the following function to it:

// Changing excerpt length
function new_excerpt_length($length) {
return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');
 
// Changing excerpt more
function new_excerpt_more($more) {
return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');

Let’s wrap it up!

By trying the above-mentioned tips and tricks you will get the chance of discovering new capabilities of your website and expand its functionality. Once you have experienced the benefits of these hacks, this will surely assist in making your content management more effective, as well. 

Hope this article was an eye-opening guide for diversifying your WordPress knowledge. If you are interested in similar blogs, feel free to check more articles on our website.

       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product       Let’s talk about your product