0

I plan to make one-page website in which any section of the page can be chosen by the Admin to be displayed or not. I've seen in some themes that it is possible to turn off some template parts to hide different sections in the output page and it always seemed too cluttered to understand it. I am not interested in just hiding them, because proper theme_mod would be enough. I would like to affect the rendering of the section at all (so it doesn't even appear in the page source). I wonder then how, by using the Customizer e.g. checkbox, could I access the get_template_part() function.

1

Simply wrap the call to get_template_part() with a conditional that checks the value of the theme mod. If it were a checkbox it would look like this:

if ( get_theme_mod( 'my_checkbox_field' ) == '1' ) {
    get_template_part( 'path/to/template' ); 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.