Tweaks on WooCommerce page title using woocommerce_page_title filter

In one of my recent WooCommerce project, I want to add a text string with all category archive page’s title. On the same project, also I want to improve the title for product search result pages.

In WooCommerce, we have a function called woocommerce_page_title and we can use this one to apply changes on WooCommerce page titles.

examples

Add a string with category archive page titles.

function change_woocommerce_category_page_title( $page_title )
{
	if ( is_product_category() ) {
		
		$page_title = "My String " . $page_title;
		
	}
	return $page_title;
}

// add the filter
add_filter( 'woocommerce_page_title', 'change_woocommerce_category_page_title', 10, 1 );

Better title for search result page

function better_woocommerce_search_result_title( $page_title )
{
	if ( is_search() ) {
		if (! get_search_query()) {
			$page_title = sprintf( __( 'Search Results: “All Products”', 'woocommerce' ), get_search_query() );
		} else {
			$page_title = sprintf( __( 'Search Results: “%s”', 'woocommerce' ), get_search_query() );
		}
	}
	return $page_title;
}

// add the filter
add_filter( 'woocommerce_page_title', 'better_woocommerce_search_result_title', 10, 1 );

There is too many creative ways to use this filter on our WooCommerce page title. Just try to tweak the code and it will give out standing page title for our stores.

Need Help?

Do you need any help on WordPress & WooCommerce? I'm happy to help you.

Contact Me

Recent Posts

  1. Update query order - WordPress
  2. Display featured products - WooCommerce
  3. Remove "Category:", "Tag:", "Author:" from the_archive_title - WordPress
  4. The essential & basic WP-CLI commands for a WordPress developer
  5. Install theme unit test data using WP-CLI - WordPress


Questions / Comments

If you found this article interesting, found errors, or just want to discuss about them, please get in touch.