Forums

Add HTML using Filter Hooks (4 posts)

  1. JonMeek
    Member
    Posted 1 year ago #

    I am trying to add some HTML code to a child theme. I know I can create templates for my child theme to override the parent theme's files, but I am trying to see if there is a way to do it in the functions.php file.

    I want to add a little HTML right after the header.php file, and then right before the footer.php file. I am thinking that filter hooks should be the way to do this, but I can't find the right hooks. Am I looking in the right direction?

  2. Does it have to be exactly right after the header and right before the footer? It's really easy to output HTML using wp_head and wp_footer filters.

    add_filter( 'wp_head' , 'your_function' );
    function your_function() {
       echo '<!-- head html code here -->';
    }

    and

    add_filter( 'wp_footer' , 'your_other_function' );
    function your_other_function() {
       echo '<!-- footer html code here -->';
    }
  3. JonMeek
    Member
    Posted 1 year ago #

    Hey Jan, thanks for the reply.

    Yep, I did try wp_head just as you suggested. The problem with that is it places the code inside the HTML <head></head> tag.

    To be a little clearer about what I'm trying to accomplish: I have created a child theme for Twenty Eleven, and I want to add a div between the "branding" and "main" divs.

  4. I have created a child theme for Twenty Eleven, and I want to add a div between the "branding" and "main" divs.

    Ah, that makes sense. Doing via hooks is attractive but I think the only way to pull it off reliably is to modify a child theme's copy of the parent template file.

Topic Closed

This topic has been closed to new replies.

About this Topic