Site logo

Archived topic

Hook question

9 replies · Started by mc208 on November 16, 2016

Viewing posts 1–10 of 10

I'm using this plugin: https://wordpress.org/plugins/insert-pages/
to insert a custom footer I made with Elementor, via shortcode into the "before footer content" hook location so that it inserts the layout on all the pages. However, I have a need to NOT display the footer on particular page. Is there some way that I can exclude certain pages from having the content displayed in that hook location?

Hi there,

You would have to use a PHP conditional: https://codex.wordpress.org/Conditional_Tags

For example:

<?php if ( ! is_page( 'my-excluded-page-slug' ) ) : ?>
    <?php echo do_shortcode( '[your-shortcode]' ); ?>
<?php endif; ?>

... or, you could use Tom's fantastic Simple CSS plugin and then on the page you do not want that custom footer to appear on, just add some CSS to the meta box in the WP editor.

.insert-page.insert-page-18 {
display: none;
}

You get the page from Appearance > Pages > All Pages and hovering over the Page where you created the footer; it will show the ID in the lower left of your screen.

May not be as eloquent, but a lot "safer" than wrangling PHP :)

Cheers!
Lyle

That's actually a better idea, especially if there will be multiple pages to hide it from.

Thanks, Lyle!

A third party added a plugin this morning:
http://www.elementoraddons.com/anywhere-elementor/
because there were issues with using the insert pages plugin method.

So now, I still use a shortcode, but it's via this other plugin and it uses the post ID, not the slug. So Tom, can I still use your PHP conditional, and how would I write it if I wanted to exclude more than one page?

Thanks

You would add an array inside the is_page function:

<?php if ( ! is_page( array( 'my-excluded-page-slug', 'another-page', 'one-more' ) ) ) : ?>
    <?php echo do_shortcode( '[your-shortcode]' ); ?>
<?php endif; ?>

Alternatively, wrap your shortcode in a div with a class, and hide it using CSS using Lyle's method.

Mike -

Make it easy for yourself ... no PHP will be harmed :) Use Tom's Simple CSS plugin and add this to the pages where you don't want the footer:

#elementor.elementor.elementor-18 {
display: none;
}

This is using the new plugin that you link to above :) Note that you have to use your own ID for the Elementor created page ID.

Cheers!
Lyle

Is there anything you DON'T know? That worked!

I have a similar problem, I have two headers I want to use GP hooks with, at the moment I am using anywhere elementor to insert in GP Hooks. What I want to do is when the visitor logs into the site it shows one header when they are logged out it shows the other. I have tried playing around with some of the examples on here but to no avail.
Any help anyone?

John -

Just tried this and it works :) Adjust the IDs to your own of course. The 440 id is the Anywhere Elementor template ID for logged in users and 444 is for logged out users (visitors).

Paste this into the appropriate GP Hook location and don't forget to tick the Execute PHP tick box.

<`?php
if ( is_user_logged_in ( ) ) {
echo do_shortcode( '[INSERT_ELEMENTOR id=440]' );
} else {
echo do_shortcode( '[INSERT_ELEMENTOR id=444]' );
}
?>`

Cheers!
Lyle

This archived topic is closed to new replies.