Home Forums ACF PRO Add a 'Select header layout' option to Options Page (ACF Pro)


Add a 'Select header layout' option to Options Page (ACF Pro)

  • So, I’ve set off on a mission to build a master theme for use in our client sites. One of the hurdles I need to overcome is making header and footer layouts selectable when setting up a new site – globally.

    For example, in my Options panel, I’d like to be able to ‘Choose site header layout’ and then pick from a dropdown list with options such as ‘Slim Full-Width Logo Left, Stacked w/Centered Logo, etc). I’m scratching my head wondering how to go about this as well as how to modify the normal call to make it work so that if no selection is made, it will run the normal (default) get_header() call BUT, if a selection is made from the dropdown, it will run the equivalent of say get_header(‘slim’) or get_header(‘stacked’) or, put another way, call the header-slim.php or header-stacked.php files.

    So far, all I’ve got is a new field group consisting of the dropdown containing header names. I’ve set it to not be required, and null is ok so that if nothing is selected it would still run the normal get_header call.

    Anyhoo, back to scratching my head… HELP! Pretty please? ?

  • get_header() can be called with an empty string or a value of false or null and all of these are the equivalent of calling the function without the name value. For example, all of these are the same


    So all you really need to do is get the option an have the values be whatever the name is. If no value is set then then default header.php will be used

    get_header(get_field('header_option_field', 'options'));
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.