Popular Filter Hooks in WordPress by Web Design London

In the WordPress there are more than 1,500 different hooks are available, which is a bit overwhelming at first. Some of the more common Filter hooks are:

  •  the_content — It is use for applied to the content of the post or page before displaying
  • the_content_rss — It is use for applied to the content of the post or page for RSS inclusion
  • the_title — It is use for applied to the post or page title before displaying
  •  comment_text — It is use for applied to the comment text before displaying
  •  wp_title — It is use for applied to the page <title> before displaying
  •  the_permalink — It is use for applied to the permalink URL

Now look at some of the most popular Filter hooks that are using in WordPress, Let’s begin with a more practical example that uses the_content Filter hook. You can alter the content of pages and posts before to it being displayed in the browser by using this hook. This hook can add your custom content either in the middle, of before, or after the content of pages or posts.

<?php
add_filter ( ‘the_content’, ‘prowp_subscriber_footer’ );
function prowp_subscriber_footer( $content ) {
if( is_single() ) {
$content.= ‘<h3>Enjoyed the articles by Web Design London</h3>’;
$content.= ‘<p>Subscribe to my
<a href=”http://www.webdirectors.co.uk/blog”>Read Articles</a>!</p>’;
}
return $content;
}
?>

The above example is adding the text to the bottom of the content of your posts. In the above example the is_single() function is also use, it means that your subscribe text is added only on a single post page. All of the post or page content stored in the $content variable, you are adding it to the bottom of your post content by appending your subscribe text. Here you aren’t actually modifying the post so this is the ideal way to add content to the bottom of all posts. Another advantage is that in the future if you need to change this message or content you can change it in one place, instead than updating every post in your website.

In WordPress another powerful Filter hook is the_title. By this hook you can change the post or page title before to being displayed. Below is an example that uses this filter hook:

<?php
add_filter( ‘the_title’, ‘prowp_custom_title’ );
function prowp_custom_title( $title ) {
$title .= ‘ – Web Design Agency London ‘;
return $title;
}
?>

The above example will add “Web Design Agency London” to all of your pages and posts titles. You should to know that this doesn’t actually modify the title in the database but rather it modifies the display of the title generated for the end user of you site. When creating a new page or post the default_content Filter hook is useful for setting the default content. If you have a set format for all of your posts so this is helpful as it can save you valuable writing time:

<?php
add_filter( ‘default_content’, ‘prowp_default_content’ );
function prowp_default_content( $content ) {
$content = ‘For more Web Design please visit Web Design Agency London ‘;
return $content;
}
?>

The Filter hooks are very powerful for inserting your own processing into a different point in the Loop processing of each post.