• Hi there,

    I got this code which lives inside the functions.php file:

    add_action('woocommerce_before_single_product', 'custom_before_single_product');
    
    function custom_before_single_product() {
    
    echo '<?php get_header(); ?>';
    
    }

    I’m trying to make the header show above the single product container (right now the navigation and the header are showing to the left side)

    Grateful for your guidance.

    • This topic was modified 1 year, 6 months ago by bcworkz. Reason: code format fixed
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator James Huff

    (@macmanx)

    I recommend getting in touch with WooCommerce’s support about this via https://woocommerce.com/my-account/create-a-ticket/ if you have any of their paid WooCommerce products or https://www.ads-software.com/support/plugin/woocommerce/ if you do not.

    Moderator bcworkz

    (@bcworkz)

    Top tip: When you post code snippets in these forums, use the Code block. If you do not, the forum’s parser will corrupt you code.

    I edited your topic to place your code in a code block, but I’m not 100% sure it copied correctly since the parser may have already corrupted it.

    If you want the entire header template content output from an action hook, you could just do
    add_action('woocommerce_before_single_product', 'get_header');
    No need to wrap in another function.

    However, you do not want the entire header template content output from an action hook! Header templates typically include <html> and <head> tags which should not be duplicated on the page. Surely by the time this action fires, those things have already been output and you mustn’t do it again.

    Calling get_header() will not resolve the layout issue you are seeing. It’s very likely your issue is CSS related and not about when or where get_header() is called. If you are able to provide a live link to a page demonstrating your layout issue, someone here might be able to suggest a solution. But TBH, James’ suggestion is best since WooCommerce support understands their single product pages better than anyone.

    Thread Starter learner79

    (@learner79)

    Hi, Sorry for not putting the code in the code block.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Header and navigation showing to the left and not on top’ is closed to new replies.