Frederic Garcia
Frederic Garcia

Reputation: 99

Changing <title> in Woocommerce page

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.

Upvotes: 3

Views: 10128

Answers (5)

Harshit Vaishnav
Harshit Vaishnav

Reputation: 69

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

Upvotes: 2

Tania J Siyam
Tania J Siyam

Reputation: 61

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

Upvotes: 6

Marek Aleszczyk
Marek Aleszczyk

Reputation: 46

This works for me:

function wp_head_wpaction0() {
    if ( is_shop() ) { ?>
        <title>Custom title</title>
    <?php }
}
add_action( 'wp_head', 'wp_head_wpaction0', 0 );

Upvotes: 2

Frederic Garcia
Frederic Garcia

Reputation: 99

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!

Upvotes: 4

skatedan
skatedan

Reputation: 103

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

$page="title";
include_once"page.php";
echo <title>$page</title>

Upvotes: 0

Related Questions