Jump to content

Dynamically change "wordpress title" based on "page template"


Recommended Posts

I have added the following code to my functions.php but its not changing the page name.

 

I have both file name and template name set to "page-FullWidthdynamic.php" 

 

I thought "is_page_template" referred to the template name rather than the file name within the themes/child themes folder.

 

 

Template Name:

/** * Template Name: page-FullWidthdynamic.php
 * @package WordPress
 * @subpackage Themetemplate
 */

functions.php code: 

function filter_wp_title( $title ) {

               // Change page title if page template is:
    if ( is_page_template( 'page-FullWidthdynamic.php' ) ) {
        return 'life is good';
    }
               // Otherwise, don't modify the document title
    return $title;


add_filter( 'wp_title', 'filter_wp_title' );


}

Maybe your page-FullWidthdynamic.php file is located in some subdirectory inside your template directory? If that's the case, you need to include subdirectory name too.

 

It's also hard to tell where and how you use the code, but be aware that this function doesn't work well inside loop.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.