Like Quertime on Facebook!

A Comprehensive Guide on WordPress Administrative Filters

Posted on by in WordPress

WordPress is enriched with some arguably important features that are either widely misunderstood or completely ignored by developers who’re engaged in handling multiple WordPress development projects. Whether it’s about mediocre WordPress development or professional WordPress development, a detailed know-how about the customized administration filters is something that will help you in implementing your projects with a broader outlook.

wordpress-hooks-filters-actions

Simply put, the basic reason behind using bespoke admin filters is to allow you to avail the amazing flexibility of extending, customizing and enhancing your WordPress web development efforts via the use of specific APIs. So, let’s get started and learn everything about these customized WordPress Administration filters that offer the much-needed spark to your WordPress web development initiatives.

What’s so special about WordPress Hooks?

WordPress Hooks basically refer to two things viz: actions and filters. These two activities actually allow you to perform tweaks to specific parts of WordPress page life cycle wherein you can choose to insert, retrieve or modify the web page data in the desired manner. Here, it is interesting to note that although actions and filters serve the same purpose, they are quite different from one another. Plus, it isn’t recommended to throw a hook into any arbitrary point of execution. There are specific durations of time when certain hooks operate and time periods when you can easily take an advantage of this situation. One of the greatest advantages of using WordPress hooks is that irrespective of whether you are a WordPress code, a plugin developer or a theme author, you can use the hooks for changing the behavior of WordPress without the need for editing any PHP source files.

Now, here are some popular custom WordPress Administration filters that you’re going to love for tweaking the overall functioning of your WordPress website:

wordpress-filter-functions

add_ping

This WordPress filter hook is being applied to every new value of the pinged field that’s available on a particular blog post under a situation where the ping is added before saving the new details into the database.

A bespoke filter for photographers

If you’re a photographer who’s showcasing his/her work via a WordPress website then you can simply paste the below mentioned code into the functions.php file for eliminating any changes for automatic compression of images:

add_filter('jpeg_quality', function($arg){return 200;});

Doing this not only saves you an incredible amount of bandwidth and loading time but it even allows you to have high-resolution, full-length images on your web pages.

A filter to remove the often frustrating ‘Read More’ Jump from WordPress blog posts

Almost all WordPress blog posts contain a “Read more” link which automatically redirects the user to the point within the blog where he/she read the end of. If you find these ‘Read more’ links quite frustrating then you can choose to jump from the same by pasting the below code into your functions.php file:

 function wdc_no_more_jumping($post) {
     return '<a href="'.get_permalink($post->ID).'" class="read-more">'.'Continue Reading'.'</a>';
}
add_filter('excerpt_more', 'wdc_no_more_jumping');

A handy filter for automatic replacement of words in your WordPress blog posts

If you’ve already named a blog and for some reason you choose to rename it to something else, it’s not necessary for you to edit all the blog posts in order to replace every since instance of the respective blog. Rather, you can simply choose to paste the below mentioned code in your functions.php file and the WordPress hook will do the job for you:

function replace_text_wps($text){
    $replace = array(
        // 'WORD TO REPLACE' => 'REPLACE WORD WITH THIS'
        'wordpress' => '<a href="#">wordpress</a>',
        'excerpt' => '<a href="#">excerpt</a>',
        'function' => '<a href="#">function</a>'
    );
    $text = str_replace(array_keys($replace), $replace, $text);
    return $text;
}

add_filter('the_content', 'replace_text_wps');
add_filter('the_excerpt', 'replace_text_wps');

A filter for adding post thumbnails to RSS Feeds

add-display-post-thumbnails-rss-feed

With this cool WordPress filter, you can easily choose a thumbnail and automatically add it to your WordPress website’s RSS Feeds. All you need to do is simply paste the below code into your functions.php file, followed by saving the file. One crucial thing that needs to be mentioned here is that for the below code snippet to work, you’ll need to have a WordPress theme that supports post thumbnails:

function cwc_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', 'cwc_rss_post_thumbnail');
add_filter('the_content_feed', 'cwc_rss_post_thumbnail');

attachment_fields_to_edit

This is a filter that’s applied to form fields which need to be displayed when the user is editing an attachment. This filter is called in the get_attachment_fields_to_edit function.

A simple-to-use filter for adding target=”blank” to all links

Since target=”blank” links might not sound appealing to every WordPress developer, it’s always been pretty much interesting to find how the global clients love to include the same in their WordPress websites. So, if you too are inclined on transforming all the links within your WordPress web pages to target=”blank”, then all you need to do is simply paste the below mentioned function into your functions.php file:

function autoblank($text) {
        $return = str_replace('<a', '<a target="_blank"', $text);
        return $return;
}
add_filter('the_content', 'autoblank');

An exclusive filter for removing comment auto-links

By default, each time a user leaves a comment(containing a specific URL) on your WordPress blog, the respective URL is being automatically transformed into a link. Although this can turn to be quite useful for the site, seeing multiple links in comments can make your blog appear spammy. Therefore, you can choose to remove these auto-links by pasting the following code in your functions.php file:

remove_filter('comment_text', 'make_clickable', 5);

Once you’re done with the code pasting process and saving the functions.php file; you’ll notice that the auto-links have disappeared from all your WordPress blog posts.

Conclusion

With a crisp and clear understanding of WordPress administrative filters, I’m sure you’d have got all geared up for applying the same to your WordPress web development projects. With actions and filters playing a critical role in empowering existing WordPress functionalities, you can definitely grab an excellent opportunity of offering your customers something new and out-of-the-box. So, its time for you to embrace these WordPress admin filters for creating that ‘ultimate’ experience for your site/blog visitors.

Author: Ben Wilson

Ben Wilson is a professional WordPress developer for a leading PSD to WordPress conversion company. He also provides conversion services like HTML to WordPress theme and many more. If you are looking for the afforsaid services feel free to contact him.

Tags: , , ,

Comments are closed.