Support » Themes and Templates » Modify Page Title Outside of Header.php

  • Resolved Casey Picker

    (@ckpicker)


    Is there a way to programmatically assign the page title outside of the header.php file?

    In one of my page template files, I would like to dynamically assign the page title based on a value in a custom field. Is this possible?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Is there a WordPress hook or anything I could use to do this?

    I was able to use a filter hook to assign a value to wp_title:

    function assignPageTitle(){
      return "Title goes here";
    }
    add_filter('wp_title', 'assignPageTitle');

    Could you explain a bit more on how you accomplished this?

    Specifically, I am looking to take the wp_title and wrap it in some standard text that’s used on all the pages for a custom post type, so authors don’t have to enter redundant info for each post.

    Looking to do this:
    <title><?php wp_title( '|', true, 'right' ); ?>STATIC CUSTOM TEXT</title>

    When I modify header.php, I do not see any changes in the browser title. I just get the title of the post.

    I created a custom page template and put the code above at the top of the page template. Then just make sure you assign the custom page template to each page that you want the title to show on.

    Thanks! So does your code retain the original page title, or replace it with the value in the custom field?

    Sorry a beginner on WP so some of this stuff is a bit out of my grasp.

    how do you assign the template to the page programmatically? I have all the templates I want, but I want to be able to assign new pages I create programmatically with a form. I can put the code to assign the template to the page in a widget, but I don’t know what code I should use for this. Any suggestions?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Modify Page Title Outside of Header.php’ is closed to new replies.