WordPress.org

Ready to get started?Download WordPress

Forums

adding header html elements in a child theme with functions.php (4 posts)

  1. lucaboccianti
    Member
    Posted 2 years ago #

    hello,

    I am designing a child theme using Twentyeleven as parent.

    I'd like to add some html elements over the header image: icons to facebook page, twitter accounts etc..

    I could manage it just pasting those icon on the header image and then using an image map, but I prefer to have the img tags called in separate div's and then styling the absolute positions of these div's via css.

    I could easily add the div's to header.php, but I would like to avoid as much as possible adding modified parent's template files to the child theme.

    The solution I am thinking is to exploit some event (hook or action) to trigger a function in the child's functions.php to add those html elements in the <body>, but I can't find a specific action to use.

    I mean, when WordPress core start writing the body, then please write also my div's and img's.

    Is this possible, and could someone give me some hint?

    thanks.

  2. wspencer
    Member
    Posted 2 years ago #

    If you're using a child theme, just copy and paste the header.php file of the parent theme and save that to your child theme. Now edit the header.php file that you just created in your child theme folder and you can just put the divs in there yourself. No need to hook to anything.

  3. lucaboccianti
    Member
    Posted 2 years ago #

    thanks for your answer. I was aware of that and this is the method I normally use.

    maybe I need to clarify my question. I was just thinking: what if the developer of the parent theme update the theme and significantly modify the parent header.php with new functionalities etc.. I would have to rewrite the child header.php.

    ok, no big deal, but maybe delegating the child functions.php to do the job would avoid the necessity of rewriting header.php.

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    Ultimately, it's going to be completely theme dependant. Some themes offer their own filters & actions, other's don't. You would need to look for a theme from the first group if you want to modify the header output via functions.php.

Topic Closed

This topic has been closed to new replies.

About this Topic