• Resolved Pete468

    (@pete468)


    I’ve read around this subject for a while now, but most solutions focus on displaying a custom header based on different categories. In my case, it ought to be simpler – I need to call one different header.php for all Category and Single Product pages (using the defualt header for cart, checkout and so on) – Howerver – its still beyond my coding ability! My link requires a log-in as the site is under construction – but I can provide one if anyone is kind enough to have a look! Thanks in advance!

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support EastOfWest a11n

    (@eastofwest)

    Hi there ????

    There might be several approaches to how to achieve this goal, and one way is to start with the get_header() function. Most themes include this function, and can be explored starting here:
    https://developer.www.ads-software.com/reference/functions/get_header/

    That page also has an example that suits your requirements (multiple headers), which you’ll find lower down on that page.

    Thread Starter Pete468

    (@pete468)

    Thanks! Thats’ a handy function. I guess, to use it to call a special header for Category and Product pages, I would need to know the names of the templates woocommerce uses for those pages – Which I guess are archive-product.php and single-product.php? I tried this:

    function get_header( $name = single-product ) {
        do_action( 'get_header', $single-product );

    But that broke the site – Guess I misunderstood?

    Hey @pete468,

    Gotcha. I would suggest taking a look at one of the example functions for some ideas on how to implement this. Here’s one as an example:

    
    <?php
    if ( is_home() ) :
        get_header( 'home' );
    elseif ( is_404() ) :
        get_header( '404' );
    else :
        get_header();
    endif;
    ?>
    

    This one uses WordPress’s conditional tags to load different headers based on what’s viewed.

    The get_header( 'home' ); will load a file named header-home.php when the is_home() conditional is true.

    You can read more about WordPress’s conditional tags here:

    https://codex.www.ads-software.com/Conditional_Tags

    WooCommerce also has ones you can use:

    https://docs.woocommerce.com/document/conditional-tags/

    I hope that gets you pointed in the right direction.

    Cheers

    Hi @pete468,

    It’s been a while since we heard from you, so I’m marking this thread resolved. Hopefully, you’ve been able to resolve this, but if you haven’t, please let open up a new topic and we’ll be happy to help out.

    Take care

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Use conditional header.php for category and procuct pages in Woocommerce’ is closed to new replies.