I would like to add a class to a page template’s body if the sidebar is not defined. How can I do that?
Leave a Reply
You must be logged in to post a comment.
I would like to add a class to a page template’s body if the sidebar is not defined. How can I do that?
You must be logged in to post a comment.
if you are using an actual page template (as selected in the dropdown panel in the admin area) then using is_page_template(‘file-name.php’) in the body_class function will do it.
then, the CSS would be body.class-name #content would apply to only that template area.
If you donât know the names of the sidebars you can use
wp_get_sidebars_widgets()
:If you know the names use
is_active_sidebar()
in that function like @s_ha_dum suggested.With php we can have this with ob_start() and ob_get_clean() but it is kinda hacky.
Better to use javascript:
I believe you need
is_active_sidebar
.Or possibly
is_dynamic_sidebar
.