Site logo

Archived topic

Can I make hooks open only on certain pages?

11 replies · Started by Anonymous on January 13, 2015

Viewing posts 1–12 of 12

This probably stems from my general inexperience with all things webdesign & programming, but is there a way that I can have a hook display only on certain pages? I am using the hooks feature to display breadcrumbs from the Yoast SEO plugin, and I have the PHP code set for "Before content". Ideally, I would only display the breadcrumbs when in full post view. Right now, the breadcrumbs display on the main blog page and category/tag pages, and I would like to be able to restrict them to just single posts.

Here's the PHP if that matters at all:

<?php if ( function_exists('yoast_breadcrumb') ) {
	yoast_breadcrumb('<p id="breadcrumbs">','</p>');
} ?>

Thanks!

You can use WordPress if conditionals: http://codex.wordpress.org/Conditional_Tags

This one specifically would be:

<?php if ( is_single() ) : ?>
      <?php if ( function_exists('yoast_breadcrumb') ) {
	yoast_breadcrumb('<p id="breadcrumbs">','</p>');
      } ?>
<?php endif; ?>

Great, the code worked excellently. Thanks a ton!

You're welcome :)

I'm also playing with the Yoast SEO plugin and have put breadcrums 'Before content' with GP Hooks.
Tom, following that link you posted I have set 'is_singular()' for the breadcrums apperaing when you open "A Single Page, a Single Post, an Attachment or Any Other Custom Post Type"

But I don't know if that's exactly what I need: I want the breadcrums to appear wherever you are (posts, pages, subpages, etc.) except when you're in the home page

Do you have a better code for that?

Merci

Hi Carlos,

You can use this code to show something on all pages except the homepage:

<?php if ( ! is_front_page() ) : ?>
      Your stuff in here
<?php endif; ?>

Awesome, that's exactly what I needed
Lot of help from you these days!

Happy to help! :)

Hi Thomas, I used this code on my site right below header, it works fine but the last image (editionRev.png> does not stay inline when I go responsive?

<div style="margin-top:-219px;margin-bottom:130px;margin-left:10%;" class="grid-container grid-parent">
patron_magazine
</div>

Hi Thomas, I used this code on my site right below header, it works fine but the last image (editionRev.png> does not stay inline when I go responsive?

<div style="margin-top:-219px;margin-bottom:130px;margin-left:10%;" class="grid-container grid-parent">
patron_magazine
</div>

Also this Div is pushed down to the Secondary Menu.

Any suggestions welcomed Thank you!

Hi there,

That's because you're using inline styles which you can't tweak for mobile.

You may want to try adding a class to your div, and then applying your css to the div when not in mobile:

@media screen and (min-width: 769px) {
      .sample-class {
            margin-top:-219px;
            margin-bottom:130px;
            margin-left:10%;
      }
}

Hi Carlos,

You can use this code to show something on all pages except the homepage:

<?php if ( ! is_front_page() ) : ?>
Your stuff in here
<?php endif; ?>

Hi Tom,

What about if I want to show the GPhook only on the front page and not on any other pages?

Br, Mark

EDIT:
Found the info in this post.

This archived topic is closed to new replies.