skip to Main Content

I am trying to change the content of the < title > tag if it’s shop. I leave here an example of what I have done:

function custom_title() {
    if ( is_shop() ) {
        // do stuff to change <title>text</title>
    }
}
add_action ('wp_head', 'custom_title');

Not sure if I am in the right way. Of course I tried to change the title on the shop page, but keeps the as "Product Archives – [site title]". Also tried to use the plugin SEO by Yoast with no results.

5

Answers


  1. Chosen as BEST ANSWER

    I found the solution with the plugin SEO by Yoast.

    Just go to "titles and meta tags" section, and then go to tab "Post types". Below there is a section with the following note: "instead of templates these are the actual titles and meta descriptions for these custom post type archive pages".

    Just change the meta info on that cell and that's it.

    See you!


  2. have you tryed to make a variable $page_title make this?

    $page="title";
    include_once"page.php";
    echo <title>$page</title>
    
    Login or Signup to reply.
  3. This works for me:

    function wp_head_wpaction0() {
        if ( is_shop() ) { ?>
            <title>Custom title</title>
        <?php }
    }
    add_action( 'wp_head', 'wp_head_wpaction0', 0 );
    
    Login or Signup to reply.
  4. This should work:

    function wc_custom_shop_archive_title( $title ) {
        if ( is_shop() && isset( $title['title'] ) ) {
            $title['title'] = 'My Title';
        }
    
        return $title;
    }
    add_filter( 'document_title_parts', 'wc_custom_shop_archive_title' );
    
    Login or Signup to reply.
  5. Try this, This will work for sure.

    function wc_custom_shop_archive_title( $title ) {
            if ( is_shop() ) {
               return str_replace( __( 'Products', 'woocommerce' ), 'Your Title', $title );
            }
            return $title;
        }
        add_filter( 'wp_title', 'wc_custom_shop_archive_title' );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search