0

How can I build a plugin which will modify a title (header) of the page?

I built one generic page which uses shortcodes to display relevant information based on url parameters, but I can't use shortcodes to generate dynamic headers.

So I tried to add "the_title" filter, but it won't update the header, it only updates title in links to another pages:

function sn_training_title($title){

    return $title."...";
}

add_filter( 'the_title', 'sn_training_title' );

here is how it looks: enter image description here

  • Usually the_content() runs after the_title() in the page.php template. – birgire Dec 7 '15 at 15:34
  • How does that impact? I'm very new to the WP development – Oleg Dec 7 '15 at 15:35
  • i.e. the title is displayed before the shortcode is generated in the_content(). Also something strange is your is_page check. – birgire Dec 7 '15 at 15:37
2

In simple words the problem with your approach is this:

The title kind of already is on his way from your server to the browser of your users when WordPress starts thinking about the content where your shortcodes are in. So this is too late.

Also if you look at what the is_page function takes as a parameter...

Page ID, Page Title or Page Slug

... you see that a shortcode isn't an option to use.

So if you are already familiar with using URL parameters why not use those directly in the filter above instead of trying to go through shortcodes?

  • I understand that I cannot use shortcodes in the title, but filter "the_title" won't modify the title of the page when viewing it as a single page, it only modifies links to other pages, not the one that I'm viewing at the moment – Oleg Dec 7 '15 at 19:29
  • I updated my snippet to make it less confusing – Oleg Dec 7 '15 at 19:30

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.