Website Building » WooCommerce » How Do I Change the Page Title in WooCommerce?

How Do I Change the Page Title in WooCommerce?

Last updated on January 12, 2023 @ 4:15 pm

WooCommerce is a powerful eCommerce plugin for WordPress. It is highly customizable and offers a lot of features to make your online store successful. One of the things you can customize in WooCommerce is the page title.

The page title is the text that appears in the browser tab when someone visits your store. By default, WooCommerce will use the name of your store as the page title. However, you may want to change this to something else, such as the name of your product or category.

Changing the page title in WooCommerce is relatively easy. You just need to add a few lines of code to your theme’s functions.php file. In this article, we’ll show you how to change the page title in WooCommerce step by step.

Before we get started, please keep in mind that you should not make any changes to your site without first creating a backup. This will ensure that you can always revert back to a previous version if something goes wrong.

Let’s get started!

Step 1: Create a Backup

The first thing you need to do is create a full backup of your WordPress site.

There are many WordPress backup plugins available, but we recommend using UpdraftPlus. It’s free and easy to use.

Once you’ve installed and activated UpdraftPlus, go to Settings » Backup and click on the ‘Create a new backup’ button. On the next screen, select all of the options and then click on the ‘Backup Now’ button.

Step 2: Edit Your Theme’s Functions.php File

Next, you need to edit your theme’s functions.php file and add the following code:

PRO TIP: If you are not familiar with code or are not comfortable making code changes to your site, we recommend that you seek help from a professional developer. Making the wrong change to your site’s code can break your site, so it’s important to be careful when making changes.
function wc_custom_change_page_title( $title ) {
global $post;

if ( is_shop() ) {
$title = "Your New Shop Title";
} elseif ( is_product() ) {
$title = $post->post_title;
} elseif ( is_product_category() || is_product_tag() ) {
$term = get_queried_object();

if ( $term ) {
$title = $term->name;
if ( is_product_category() ) {
$parents = get_ancestors( $term->term_id, 'product_cat' );
foreach( array_reverse( $parents ) as $parent ) {
$ancestor = get_term( $parent, 'product_cat' );
if ( !is_wp_error( $ancestor ) && $ancestor ) {
$title .= ' › ' . esc_html( stripslashes( strtolower($ancestor->name) )); } } } } } 
return stripslashes( strtolower($title) ); } 
add_filter('pre_get_document_title', 'wc_custom_change_page_title');
?>
Drew Clemente

Drew Clemente

Devops & Sysadmin engineer. I basically build infrastructure online.