Return to Snippet

Revision: 62656
at March 5, 2013 12:00 by Internet-Uzver


Updated Code
<?php

/* Disables widget areas. */
add_filter( 'sidebars_widgets', 'remove_sidebars' );

function remove_sidebars( $sidebars_widgets ) {
	global $wp_query;

	if ( is_singular() ) {
		$template = get_post_meta( $wp_query->post->ID, "_wp_{$wp_query->post->post_type}_template", true );

		// Disables all widgets
		if ( preg_match("/(-no-widgets.php)$/i", $template ) )
			$sidebars_widgets = array( true );

		// Disables 'primary' & 'secondary' sidebars widgets
		if ( preg_match("/(-no-sidebars.php)$/i", $template ) )
			$sidebars_widgets['primary'] = false;
			$sidebars_widgets['secondary'] = false;
	}

	return $sidebars_widgets;
}

?>

Revision: 62655
at March 5, 2013 11:57 by Internet-Uzver


Initial Code
<?php

/* Disables widget areas. */
add_filter( 'sidebars_widgets', 'remove_sidebars' );

function remove_sidebars( $sidebars_widgets ) {
	global $wp_query;

	if ( is_singular() ) {
		$template = get_post_meta( $wp_query->post->ID, "_wp_{$wp_query->post->post_type}_template", true );

		// Disables all widgets
		if ( preg_match("/(no-widgets.php)$/i", $template ) )
			$sidebars_widgets = array( true );

		// Disables 'primary' & 'secondary' sidebars widgets
		if ( preg_match("/(no-sidebars.php)$/i", $template ) )
			$sidebars_widgets['primary'] = false;
			$sidebars_widgets['secondary'] = false;
	}

	return $sidebars_widgets;
}

?>

Initial URL

                                

Initial Description
Disable (remove) some sidebars, or widgets at all in **Wordpress** on page template with suffix in the template name (*-no-widgets.php, *-no-sidebars.php)

Initial Title
wordpress | disable sidebars, widgets on page template

Initial Tags
wordpress

Initial Language
PHP