Append text after wordpress title

I would like to know is there a hook in wordpress to edit prefix and postfix of the_title in wordpress.

The code in content.php

the_title( 'h1 class="entry-title"', '/h1' );

I would like to add content after the closing tag of h1.

When I use the_title hook the content is added inside the h1 tag.

Like to know how to add outside the h1 tag by using action hook (fron the plugin).

Topic title Wordpress

Category Web


You can use it that way :

function add_suffix_to_title($title, $id = null){
    if (! is_admin()) {
        return '<h1>'.$title.'</h1> Your Suffix';
    }
    return $title;
}

add_action( 'the_title', 'add_suffix_to_title', 10, 1 );

And when you invoke the "the_title" function remove the h1 tag :

the_title();

I hope that would help you.


Please try this

the_title( '<h1 class="entry-title">', 'YOUR CUSTOM CONTENT</h1>' );

Using get_the_title() will work for you:

<h1><?php echo get_the_title(); ?></h1><span>YOUR CUSTOM CONTENT</span>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.