skip to Main Content

I am creating a plugin and I want to create a full-width div at the bottom of the header. I tried wp_head action but it is adding the div at the top of the header.
The question is how can i add a div at the bottom/end of header with php code? Is there any wordpress hook or filter which I can use? Thanks in advance.

Currently, it appears like this.

enter image description here

But I want to move the breaking section below the header.

2

Answers


  1. Chosen as BEST ANSWER

    Actually, there is no available WordPress hook that will run right after the WordPress header.php loads.

    I implemented this by appending the HTML code below the header using javascript.

    You can find the code here. https://github.com/AwaisTheDev/wordpress_breaking_news_plugin/blob/main/includes/load-widget-frontend.php#L82


  2. wp_body_open fires after the opening body tag but the header is after the tag. The action hook that fires after get_header would be loop_start, unless the theme has a hook added in between. Also make sure to set the priority so the hook loads first.

    Styles

    #banner {
        width: 100%;
        padding: 1rem;
        text-align: center;
        background-color: navy;
        color: white;
    }
    

    Function and hook

    function namespace_my_function() {
    ?>
    <div id="banner">
        <p>
            Breaking News! This is the banner for the news part of the header!
        </p>
    </div>
    <?php
    }
    add_action( 'loop_start', 'namespace_my_function', 1 );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search