Skip to main content
edited body
Source Link

If the parent theme does not declare support for title-tag you can do it like this in child theme

/**
 * Theme support chouldshould be added on `after_setup_theme`
 */
function add_theme_support_child() {

    add_theme_support( 'title-tag' );

}

add_action( 'after_setup_theme', 'add_theme_support_child', 11 );

Filter document_title_parts expected return type array, like this, be sure to change the if condition as per your requirements, or remove it completely to change the title throughout the site just for testing if it works.

/**
 * Change title of a page conditionally
 * 
 * @return $title - type array
 * $title['title'] - Page Title
 * $title['tagline'] - Site Tagline
 */
function change_title_for_a_template( $title ) {

    // Check if current page template is 'template-homepage.php'
    if ( is_page_template( 'template-homepage.php' ) ) {
        $title['title'] = 'Changed title for a template';
    }

    return $title;

}

add_filter( 'document_title_parts', 'change_title_for_a_template' );

Can you try thes two functions?

If the parent theme does not declare support for title-tag you can do it like this in child theme

/**
 * Theme support chould be added on `after_setup_theme`
 */
function add_theme_support_child() {

    add_theme_support( 'title-tag' );

}

add_action( 'after_setup_theme', 'add_theme_support_child', 11 );

Filter document_title_parts expected return type array, like this, be sure to change the if condition as per your requirements, or remove it completely to change the title throughout the site just for testing if it works.

/**
 * Change title of a page conditionally
 * 
 * @return $title - type array
 * $title['title'] - Page Title
 * $title['tagline'] - Site Tagline
 */
function change_title_for_a_template( $title ) {

    // Check if current page template is 'template-homepage.php'
    if ( is_page_template( 'template-homepage.php' ) ) {
        $title['title'] = 'Changed title for a template';
    }

    return $title;

}

add_filter( 'document_title_parts', 'change_title_for_a_template' );

Can you try thes two functions?

If the parent theme does not declare support for title-tag you can do it like this in child theme

/**
 * Theme support should be added on `after_setup_theme`
 */
function add_theme_support_child() {

    add_theme_support( 'title-tag' );

}

add_action( 'after_setup_theme', 'add_theme_support_child', 11 );

Filter document_title_parts expected return type array, like this, be sure to change the if condition as per your requirements, or remove it completely to change the title throughout the site just for testing if it works.

/**
 * Change title of a page conditionally
 * 
 * @return $title - type array
 * $title['title'] - Page Title
 * $title['tagline'] - Site Tagline
 */
function change_title_for_a_template( $title ) {

    // Check if current page template is 'template-homepage.php'
    if ( is_page_template( 'template-homepage.php' ) ) {
        $title['title'] = 'Changed title for a template';
    }

    return $title;

}

add_filter( 'document_title_parts', 'change_title_for_a_template' );

Can you try thes two functions?

Source Link

If the parent theme does not declare support for title-tag you can do it like this in child theme

/**
 * Theme support chould be added on `after_setup_theme`
 */
function add_theme_support_child() {

    add_theme_support( 'title-tag' );

}

add_action( 'after_setup_theme', 'add_theme_support_child', 11 );

Filter document_title_parts expected return type array, like this, be sure to change the if condition as per your requirements, or remove it completely to change the title throughout the site just for testing if it works.

/**
 * Change title of a page conditionally
 * 
 * @return $title - type array
 * $title['title'] - Page Title
 * $title['tagline'] - Site Tagline
 */
function change_title_for_a_template( $title ) {

    // Check if current page template is 'template-homepage.php'
    if ( is_page_template( 'template-homepage.php' ) ) {
        $title['title'] = 'Changed title for a template';
    }

    return $title;

}

add_filter( 'document_title_parts', 'change_title_for_a_template' );

Can you try thes two functions?