• How do I dynamically set the page title? I would like to specify the page title before wp_head is passed, so that the <title> tag will output whatever I want. I’ve searched for a while but can’t find a simple solution.

    I don’t want to display or return wp_title – I want to dynamically SET it before it’s output to the page from within a custom content type, ie.

    set_wpl_title(‘My Custom Title’);

    And when wp_head is called, all the other stuff is included plus

    <title>My Custom Title</title>

    Any simple way of achieving this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • i’d like to do exactly the same thing.
    did you have any luck so far?

    Thread Starter nexusmedia

    (@nexusmedia)

    Not really, but I created a bit of a hack to achieve what I was trying to accomplish:

    So wherever I wanted the customize the page title, I would set a global variable containing the required title and then call get_header():

    global $title;
    $title = 'My Custom Title';
    get_header(); ?>

    And then the header.php page looks like this:

    <? global $title; ?>
    <? if ($title): ?>
    <title><?=$title?></title>
    <? else: ?>
    <title>
    <? wp_title('');?>
    </title>
    <? endif; ?>

    This could be shorthanded with a ternary syntax:

    <? global $title; ?>
    <? ($title) ? $title : wp_title('') ;?>

    So not the cleanest solution, but it got the job done.

    for some reason, the short version doesn’t work for me. the long one, however, works perfectly.
    thanks very much!

    (side note: when using the “all in one SEO” plugin, it needs to be deactivated on the concerned pages)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Dynamically changing the page title?’ is closed to new replies.