So, I'm building a new theme based on Underscores. So far, I've managed to get ACF Pro to call different header files from a dropdwon selction in the Options page but, now I am faced with the task of determining how best to handle the css for each of the custom header files and how to load widget areas based on which header file is loaded.
First the css bit: Since the Underscores theme has very minimal style rules out of the box, I was thinking that it might not be a bad idea to include header-specific css files based on the header file being called by ACF Pro in the Options page. For example, I'd create a header file called header-slim.php and in my functions file, do some sort of 'if' header=header-slim.php, then load header-slim.css. This way, i would only only be loading a small css file for the chosen header, a normal style.css file, and then, for different footers, a footer.css file (ex: footer-full-width.css).
If this is an acceptable way to go about the multiple header layout concept, then what, exactly would I put in my functions file? Another detail is that if no header layout option is chosen, the theme will run the normal get_header() as a default function.
Now for the header widgets: Correct if I am wrong (which is often) but, if I load header1.php file and it has 3 widget areas in it, then those three widgets would automatically appear in the available widgets on the widgets page in WP Admin, right? Of course, after loading a header I'd need to refresh the widgets page and, so long as those widgets areas have been registered in my functions file, they would load provided there is a header file that calls said registered widgets, correct?
I've done quite a lot of digging around here and on the web in general and I've yet to find anything that addresses my questions specifically. If there is something here and I've missed it, please forgive me.
I would love some specific help with what I'm trying to achieve if you guys don't mind.
Many thanks! Ray
UPDATE: Here's some code bits for you to have a look at.
This is what I have at the top of my index.php file in order to print whichever header is selected in the ACF Pro options page:
<?php $selectHeader = get_field( 'select_header_layout','option'); if($selectHeader == "black"){get_header('black');} elseif($selectHeader == "gray"){get_header('gray');} elseif($selectHeader == "red"){get_header('red');} else {get_header();} ?>
And here's what I've added to my functions.php file - I edited the 'chosen_header' to 'select_header_layout' so as to match what I have in the index.php file. Here comes the mess...
function my_header_css_scripts () { switch (get_field ('select_header_layout', 'option')) { case 'header-black.php': $appropriateHeader = 'header-black.css'; break; case 'header-gray.php': $appropriateHeader = 'header-gray.css'; break; case 'header-red.php': $appropriateHeader = 'header-red.css'; break; default: $appropriateHeader = 'header-default.css'; break; } wp_enqueue_style ('my_header_css_scripts', get_theme_file_uri('/wp-content/themes/rm-acf1/hdr-styles/' . $appropriateHeader)); } add_action ('wp_enqueue_scripts', 'my_header_css_scripts');
Here's the code I have in my functions.php file right now (Jan 4, 2016 @ 4:30pm):
function my_header_css_scripts () { switch (get_field ( 'chosen_header', 'option' )) { case 'header-black.php': $appropriateHeader = 'header-black.css'; break; case 'header-gray.php': $appropriateHeader = 'header-gray.css'; break; case 'header-red.php': $appropriateHeader = 'header-red.css'; break; default: $appropriateHeader = 'header-default.css'; break; } wp_enqueue_style( basename( $appropriateHeader ), get_template_directory_uri() . '/hdr-styles/' . $appropriateHeader ); } add_action ('wp_enqueue_scripts', 'my_header_css_scripts');
print_r( get_field ( 'select_header_layout', 'option' ) );
?get_field ('select_header_layout', 'option')
to make sure it meets one of your conditions. Otherwise it'll always be loading the default CSS.