Skip to main content
Removed second question, off topic
Source Link

In my header.php file, I've been trying to retrieve the slug of the current page, to check it's WooCommerce Products Archive/shop page. I followed this similar question's answer, to no avail; instead of the current page's slug being returned, the first item being sold slug was returned. My questions are these:

  • Why isdoes $post->post_name return test-product-magazine, instead of the correct, shop?
  • How can I create a custom Page Template for WooCommerce Products Archive/shop page?

test-product-magazine, instead of the correct, shop

<?php 
    global $post;
    echo "post_name: " . $post->post_name;
?>

In my header.php file, I've been trying to retrieve the slug of the current page, to check it's WooCommerce Products Archive/shop page. I followed this similar question's answer, to no avail; instead of the current page's slug being returned, the first item being sold slug was returned. My questions are these:

  • Why is test-product-magazine, instead of the correct, shop?
  • How can I create a custom Page Template for WooCommerce Products Archive/shop page?

test-product-magazine, instead of the correct, shop

<?php 
    global $post;
    echo "post_name: " . $post->post_name;
?>

In my header.php file, I've been trying to retrieve the slug of the current page, to check it's WooCommerce Products Archive/shop page. I followed this similar question's answer, to no avail; instead of the current page's slug being returned, the first item being sold slug was returned. My questions are these:

  • Why does $post->post_name return test-product-magazine, instead of the correct, shop?

test-product-magazine, instead of the correct, shop

<?php 
    global $post;
    echo "post_name: " . $post->post_name;
?>
edited tags
Link
Source Link

Global variable $post returning incorrect object

In my header.php file, I've been trying to retrieve the slug of the current page, to check it's WooCommerce Products Archive/shop page. I followed this similar question's answer, to no avail; instead of the current page's slug being returned, the first item being sold slug was returned. My questions are these:

  • Why is test-product-magazine, instead of the correct, shop?
  • How can I create a custom Page Template for WooCommerce Products Archive/shop page?

test-product-magazine, instead of the correct, shop

<?php 
    global $post;
    echo "post_name: " . $post->post_name;
?>