0

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).

0

Using get_the_title() will work for you:

<h1><?php echo get_the_title(); ?></h1><span>YOUR CUSTOM CONTENT</span>
  • I am not asking for a solution to edit the theme file. I am interested in a action hook which will help me to do it from the plugin. – siva prasanna Oct 20 '16 at 12:28
0

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.

-1

Please try this

the_title( '<h1 class="entry-title">', 'YOUR CUSTOM CONTENT</h1>' );
  • 1
    Please read the question: "I would like to add content after the closing tag of h1." :) – fuxia Jun 7 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.