Skip to main content
3 of 3
Removed second question, off topic

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 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;
?>