Archived topic
Top Bar Widget only on home page
5 replies · Started by Ria on July 18, 2018
I have a static home page on a fairly large site. I have a top bar widget area set up that looks and works great - but I want it to load ONLY on the home page, not site-wide. I don't want to have to manually click the "disable elements" in the editor for this on every page/post/archive. I don't want to use css to 'display:none'. And I don't want to install a big widget plugin just for this one simple task.
What I want is to use a simple line of conditional PHP code in functions.php to do this. I know it's simple, but I'm not a PHP coder, so not able to put the pieces together on my own. So far, all I have is:
<?php
if ! is_front_page() || if ! is_home() {
// Put code here to not load the top bar widget.// < - this is the part I don't know!
}
?>
Can anyone help me with this?
Hi there,
This would be super easy and no code required using the upcoming Elements module in GP Premium 1.7.
It's currently in second beta so pretty stable in my opinion. Would you consider it?
https://docs.generatepress.com/article/beta-testing/
That's great but even though I've activated beta updates on this dev site, I'm not getting any beta updates at all? Still sitting here with GP Premium v1.6.2. I wasn't even aware there was a beta 1.7.
Is there a way to access/download/install the beta?
Or, can you help me with that line of PHP code I need?
Hi there,
sometimes there can be a 24hr delay for the WP cache to clear for the beta to show. I'll let Tom know as he is been looking into a couple of reports regarding this. But you may want to try clearing any server caches and then check the WP Dashboard > Updates and span the Check button a few times.
In the meantime you can try adding this:
add_action( 'wp', 'db_disable_topbar' );
function db_disable_topbar() {
if ( ! is_home() && ! is_front_page() ) {
remove_action( 'generate_before_header','generate_top_bar', 5 );
}
}
Thank you, David! :)
You're welcome. Hopefully the Beta (or live version) of 1.7 reaches you soon. It really is something special :)