Forums

[resolved] Creating custom "title" tag for just one single page (6 posts)

  1. dave920
    Member
    Posted 1 year ago #

    Hi all

    I'm trying to spit out a specific //title// in the //head// for Pages based on

    1) Whether the page is a specific page I want a custom title for
    2) Whether the page is ANY OTHER PAGE except that specific one

    Here's what I have so far, that isn't working ("15291" is the Page ID number):

    <?php if(is_page('15291')) {
      This is the title for the SPECIFIC PAGE
    }
    else(is_page()) {
      This is the title for ANY OTHER PAGE
    }
    ?>

    Any idea why this isn't working? What do I need to change to get the required result?

    Thanks!

  2. Kafkaesqui
    Moderator
    Posted 1 year ago #

    Try this:

    <?php if( is_page('15291') ) { ?>
    
    This is the title for the SPECIFIC PAGE
    
    <?php } elseif( is_page() && !is_page('15291') ) { ?>
    
    This is the title for ANY OTHER PAGE
    
    <?php } ?>
  3. dave920
    Member
    Posted 1 year ago #

    That totally looks like it should work, actually.

    Unfortunately, it doesn't. I'm getting this error:

    Parse error: syntax error, unexpected '{' in /home/public_html/wp/wp-content/themes/theme-name/header.php on line 20

  4. whooami
    Member
    Posted 1 year ago #

    <?php if( is_page('2') ) {
    ?>
    <title>This is the title for the SPECIFIC PAGE</title>
    <?php
    }
    if ( is_page() && !is_page('2') ) {
    ?>
    <title>This is the title for ANY OTHER PAGE</title>
    <?php }
    ?>

    that works. change the page number, obviously.

  5. Kafkaesqui
    Moderator
    Posted 1 year ago #

    Made a mistake (!!), using else instead of elseif. Fixed it in code above. whooami's stuff will do as well. ;)

  6. dave920
    Member
    Posted 1 year ago #

    YES! Success!

    Exactly what I needed. Thanks so much for your prompt response.

    In case you were wondering, I needed this function because I'm using a static page as my homepage, and I didn't want it to have the same //title// structure as every other page -- so I set the //title// page ID to its own unique title.

    Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic