No header.php in child theme – where to put code?
-
Hello Tom,
First of all thanks for such a beautiful plugin π
I’m building a website offline and really wish to place the slider in the header. I’m using the framework ‘Genesis’ by StudioPress and the child theme ‘Genesis Sample’. This child theme supports a custom header (http://my.studiopress.com/themes/genesis/), so I guess it should be possible to use the slider in the header.
I had a look at your nice tutorial about how to do it. But my “problem” is, that there is no file called header.php located in the folder of the child theme.
There is however a file called header.php located in the folder of the parent theme, Genesis, but it has this warning:
“WARNING: This file is part of the core Genesis Framework. DO NOT edit this file under any circumstances. Please do all modifications in the form of a child theme.”
And even if I wanted to go ahead anyway and paste the code into the core file, the code looks quite different from the code shown in your video demo.I’ve tried including the slider on a regular page of the website with no problem at all – it displays beautifully. However I really wish to place it in the header of my site and I simply can’t tell in which file to put the code, cause the file in which it’s supposed to be placed seems non-existent.
Do you have any experience with this issue?
Help, help, pretty please π
Kind regards – and thanks in advance,
Stine
-
HI Stine,
Just copy that header.php file over to your child theme, then modify it. The code inside header.php will look different for every theme, but take a close look and you should be able to work out where the different elements are (header, navigation etc) and paste the shortcode in where you think it should go.
If it doesn’t work the first time, try a different location until you get it right – there’s nothing wrong with trial and error π
Alternatively, your theme might have a settings page which allows you to specify some HMTL/PHP to include just below the header, it’s worth looking there first.
Regards,
Tom.Hi Tom,
Thank you so much for your great answer π I’ve tried both of your solutions, and they both work beautifully.
Actually I think it would look even better having the slider right under the navigation as shown in your demo video. I have tried pasting the code different places in my child themes header.php file, but the slider either goes above the navigation and title of the site, doesn’t do anything or gives me an error message when loading the page.
This is my full header.php code:<?php do_action( 'genesis_doctype' ); do_action( 'genesis_title' ); do_action( 'genesis_meta' ); wp_head(); //* we need this for plugins ?> </head> <?php genesis_markup( array( 'html5' => '<body %s>', 'xhtml' => sprintf( '<body class="%s">', implode( ' ', get_body_class() ) ), 'context' => 'body', ) ); do_action( 'genesis_before' ); genesis_markup( array( 'html5' => '<div %s>', 'xhtml' => '<div id="wrap">', 'context' => 'site-container', ) ); do_action( 'genesis_before_header' ); do_action( 'genesis_header' ); do_action( 'genesis_after_header' ); genesis_markup( array( 'html5' => '<div %s>', 'xhtml' => '<div id="inner">', 'context' => 'site-inner', ) ); genesis_structural_wrap( 'site-inner' );Do you see, where the slider code is supposed to go if I would like to put it right below the navigation of my site?
Thanks in advance π
Kind regards,
StineHi Stine,
It’s not too easy to say, but try under “do_action( ‘genesis_after_header’ );”, if not.. keep working your way down.
The code in the header suggests there might be a ‘Header Code’ section in your theme settings where you can specify custom code to output below the header – I would check that first before modifying the files.
Regards,
Tom.Fantastic – thank you very much! I tried adding the code right after “do_action( ‘genesis_after_header’ );” again. Last time I got an error, but this time I deleted the <?php tags – and it works! Yay π
There is indeed a ‘Header Code’ section in my theme settings, however if I paste the slider code there, the slider goes above the navigation.
It might be possible to add some more code there to make the slider go below the navigation, however I have no clue how to write this π
As long as copying the header.php file to the child theme and then modifying it doesn’t break anything, this solution is fine with me πLast question (I promise) – do you know if it could cause problems that I have duplicate code in the two header.php files?
Kind regards,
StineHi Stine,
Nope it wont cause problems, that’s how child themes work – if the file exists in the child theme then WordPress will use it (instead of the one in the parent theme). This means you can make all your custom changes in your child theme, but still apply updates to the parent theme without losing your changes.
Regards,
Tom.Hi Tom,
Thank you so much for all your help, I appreciate it!
Have a great weekend πKind regards,
StineYou’re welcome – thanks for the review!
No problem π
The topic ‘No header.php in child theme – where to put code?’ is closed to new replies.