Check if page has a sidebar

A simple filter to make smart decisions.

PHP HTML CSS JS
Click to copy

Example: Enqueue a script only if the page has a sidebar.

function my_enqueue_function() {
	if ( md_has_sidebar() )
		wp_enqueue_script( 'my-script', 'http://domain.com/script.js', array( '' ), '', true );
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_function' );
Click to copy
Click to copy
Click to copy

Check if page has sidebar

To check if the current page has the sidebar enabled, use the md_has_sidebar() conditional tag.

Use this tag to check if the Main Sidebar (or custom sidebar) is enabled on the page. Detects settings from the MD Layout panel to make this function more precise based on the page’s settings.

Labs

Get the latest MD sent straight to your inbox

There's always something new in the works in the MD Labs! Join the email list to get the newest content and releases sent straight to your inbox.*

Join the MD Newsletter

* I only email you when there's something new, or to share an exciting MD sneak peak.