Archived topic
Disable header, footer and GP Elements if URL parameter
7 replies · Started by Matthew on June 24, 2021
Hi
Is there a way to disable the header, footer and active GP elements for the page if the URL parameter "content-template-id" is present?
Thanks
Hi Matthew,
You can create a Layout Element and use it's Disable element tab to remove the header and footer to the page.
And then set the filter condition for the URL param.
Example:
add_filter( 'generate_layout_element_display', function( $display, $element_id ) {
if ( 99 === $element_id && isset( $_GET['your-url-param'] ) && $_GET['your-url-param'] == value_here ) {
$display = true;
}
return $display;
}, 10, 2 );
Where 99 is the layout element's ID.
As for removing the GP elements, you filter them the same way except you'll have to set $display = false; so they don't display.
Example: disabling block element id 123 on pages with URL param.
add_filter( 'generate_block_element_display', function( $display, $element_id ) {
if ( 123 === $element_id && isset( $_GET['your-url-param'] ) && $_GET['your-url-param'] == value_here ) {
$display = false;
}
return $display;
}, 10, 2 );
Hey Elvin
Thanks a lot for this, really appreciate it. I got the first snippet working absolutely fine, but the second one does not seem to work?
Here is the exact code I am using:
add_filter( 'generate_block_element_display', function( $display, $element_id ) {
if ( 46399 === $element_id && isset( $_GET['web'] ) && $_GET['web'] == yes ) {
$display = false;
}
return $display;
}, 46399, 2 );
It can't be anything to do with the URL parameter as I am using the exact same for the first snippet with no issues? :-/
Hi there,
in the last line of your code you have:
}, 46399, 2 );
try changing it to:
}, 10, 2 );
The 10 value there is the priority not the ID - ill update Elvins topic to make that clearer :)
Hey David
Tried changing this to 10 but have the same issue.
The actual element in GeneratePress I am trying to disable has a priority of 1, not sure if this means this is of higher importance so the code does not work? Not sure if lower is better or higher is.
Thanks.
The second element you're trying to disable - is it a Block Element ?
If it is then can you share the two code that you have so far.
If it isn't what element is it ?
Hi David,
No sorry it is a "hook" - I think maybe this is whats causing the issue?
Thanks.
Yep :)
There are several different filters for each of the element types - but we added a global one in the last update.
In the codes change: generate_block_element_display to: generate_element_display
That will work with any of the element types