Jump to content

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


DaveSandwich

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' );


}
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.