No results found. Try again with different words?

Search must be at least 3 characters.

β€Ή BACK TO DOC

Display Conditions for Blocks

Introducing the Display conditions for the WordPress and Spectra blocks from the Spectra for v1.21.0. Basically, the Display conditions are the options on which you would like to hide the block based on User Role, Browser, etc.

You can find the Display Conditions settings under the Advanced section of the respective blocks.

Let’s see the options or conditions on which you can hide the block –

  • Hide for User Role – None, Administrator, Editor, Author, Contributor, Subscriber
  • Hide on Browser – Internet Explorer, Google Chrome, Opera Mini, Opera, Safari, Microsoft Edge
  • Hide on Operating System – iOS, Android, Windows, OpenBSD, SunOS, Linux, Mac OS
  • Responsive Visibility – Hide on Desktop/Tablet/Mobile
  • User State – Logged In, Logged out users

How to disable Block Display Conditions for specific post types?

1) To disable the Block display conditions from all post types.

add_filter( 'enable_block_condition', '__return_false' );

2) To disable the Block display conditions for Page post type.

add_filter( 'enable_block_condition', function( $default = true) {
	if (isset($_REQUEST['post_type']) && 'page' === $_REQUEST['post_type']) {
        return false;
    } elseif (isset($_GET['post']) && 'page' === get_post_type($_GET['post'])) {
        return false;
    }
	return $default;
} );

3) To disable the Block display conditions for Post.

add_filter( 'enable_block_condition', function( $default = true) {
    global $pagenow;
    if(in_array( $pagenow, array( 'post.php', 'post-new.php' ) )){
        if (isset($_REQUEST['post_type']) && 'page' === $_REQUEST['post_type']) {
            return true;
        } elseif (isset($_GET['post']) && 'page' === get_post_type($_GET['post'])) {
            return true;
        }
        return false;
    }

	return $default;
} );

Note:

The above settings will only work on the live page. That means choose your desired settings, Publish/Save the page and preview the settings while you are not inside the editor and logged out if required.

Was this article helpful?


Did not find a solution? We are here to help you succeed.

Get access to growing library of 40+ innovative widgets and 300+ creative templates.

Ultimate Addons for Gutenberg Is Now Spectra - 

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Scroll to Top