Site logo

Archived topic

Further to GP Hooks

7 replies · Started by Lyle on November 25, 2016

Viewing posts 1–8 of 8

Hi Tom,

Thought that I would ask here if that's OK.

Further to this post from the GP Addon forum:

https://generatepress.com/forums/topic/hook-question/

You posted this as a PHP solution for an array of pages to exclude:

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

This works great with the GP Hooks :) However, how would one adjust this code to also exclude a post category named Blog? I tried a few things, even from Stack Overflow, but all I got were errors on those post pages :(

Any assistance will be greatly appreciated and I promise to get some GP and GP Premium tutorials up ASAP :)

Cheers!
Lyle

Conditionals can get pretty complex when you start having multiple parameters.

You could try this:

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

Hmm, once I updated with that code (using my values for pages and the blog category (as that is what it is named), the shortcode now displays everywhere :)

I may just end up doing this scenario manually :)

Basically, what I am trying to achieve is have a notice (created with Elementor and using the AnyWhere ELementor plugin shortcode to display it) displayed on all of the SV tutorial pages only and nowhere else. That is why I was thinking, OK, use the !page and list all the main menu items and then the !category so as not to appear on the posts in that category.

I could manually add that shortcode to each of those tutorial pages, but the hook method would make it "auto-magic" for all new tutorial pages ... just me being lazy :)

Hi Lyle

Maybe its easier to target a specific category/ page than excluding everything else except that category/page?

You could put all the tutorials in a tutorial category and target that tutorial page/ and category?

Hi Jamal,

Yes, that would probably work better but unfortunately all the tutorials are pages, not posts.

Looking at your site i see /tutorials/tutorial-name, are you using Tom's wpsp plugin? maybe its possible to target wpsp_id?

Sorry if that doesnt help either.

Only using WPSP for the Tutorials page, the individual tutorial pages are just pages.

But it's a moot point now ... for the time being anyway ... as I have just finished manually adding the shortcode to each of the required pages :)

I'll maybe revisit this later, but for now, I'll mark it Resolved.

If you need more help with that conditional in the future just let me know :)

This archived topic is closed to new replies.