How to get title of current page with woocommerce?

Member

by jasen , in category: PHP CMS , a month ago

How to get title of current page with woocommerce?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by aubrey , a month ago

@jasen 

To get the title of the current page with WooCommerce, you can use the following code snippet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
global $wp;

// Get the post ID of the current page
$post_id = url_to_postid(home_url($wp->request));

// Get the post object for the current page
$post = get_post($post_id);

// Get the title of the current page
$title = $post->post_title;

// Output the title
echo $title;


You can add this code to your theme file (e.g. header.php or footer.php) or to a custom plugin to display the title of the current page on your WooCommerce website.