• JonMeek

    (@jonmeek)


    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?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    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 -->';
    }
    Thread Starter JonMeek

    (@jonmeek)

    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.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    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.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Add HTML using Filter Hooks’ is closed to new replies.