Ultimate Member in Bricks: Ignoring the Content Restriction for Header/Footer

If using Ultimate Member to restrict the main post content in a template, you may run into an issue when using Bricks’ rich text elements inside your header or footer.

The issue is that when the ‘Restrict access to this posts’ is enabled it won’t just restrict the post content. It will also restrict access to any rich text elements that have been used inside of the header or footer templates (the reason being that they all use the same ‘the_content’ filter).

This means you could end up with parts of the header missing on the pages where just the post content should be hidden.

Ignore the Content Restriction

Ultimate Member has a handy filter named ‘um_ignore_restricted_content’, which allows us to ignore the current restriction logic for that post and therefore can be used to force content to be output.

We can set this ignore to be true for just Bricks’ header and footer using the following code inside a child theme or a code snippet plugin..


function bl_ignore_content_restriction() {
	add_filter( 'um_ignore_restricted_content', '__return_true' );

function bl_return_content_restriction() {
	remove_filter( 'um_ignore_restricted_content', '__return_true' );

add_action( 'bricks_before_header', 'bl_ignore_content_restriction');
add_action( 'bricks_after_header', 'bl_return_content_restriction');
add_action( 'bricks_before_footer', 'bl_ignore_content_restriction');
add_action( 'bricks_after_footer', 'bl_return_content_restriction');


That’s it

This will make sure the restriction is ignored for anything inside both the header and the footer, while leaving the content area untouched and following the post content restrictions as set in the settings.



Instant access to 390+ Bricks code tutorials with BricksLabs Pro

Leave the first comment