A Simple Guide to Customize WordPress the_title() with add_filter() – WordPress Tutorial

By | April 4, 2020

In wordpress, we often use the_title() to display or return the title of one post. In this tutorial, we will introduce you on how to customize this fucntion.

wordpress the_title() function tutorials and examples

The function is:

<?php the_title( $before, $after, $echo ); ?>

Where $echo = false, it will return the title of one post, true will display it.

To customize this function we shoud use add_filter().

For example: we want to add Free Download at the end of post title. We can do like this in your theme functions.php.

Define a function get customize title, the input parameter is post title.

function myTitle($title){
    return $title." Free Download";
}

Add it to add_filter()

add_filter( 'the_title', myTitle);

Leave a Reply