Custom WooCommerce Shop page title

Use this snippet to display custom <title> tags on your WooCommerce shop page:

/**
 * Use the user defined shop page title instead of built-in `Products` title.
 *
 * @param string $title Page Title.
 * @return string
 */
function apcom_custom_shop_title( $title ) {
	if ( is_shop() && isset( $title['title'] ) ) {
		$title['title'] = get_the_title( wc_get_page_id( 'shop' ) );
	}
	return $title;
}
add_filter( 'document_title_parts', 'apcom_custom_shop_title' );

What does this do?

By default, the shop page title for WooCommerce is overwritten by Products irrespective of the custom title you’ve added:

Default shop page title – `Products`

Using the snippet above, you can use the custom title you define under WP Admin > Pages for the shop page:

Usage:

You can either place the snippet on your child themes functions.php or use a plugin like Code Snippets to add the snippet.

Leave a Reply

Your email address will not be published.