Can I make hooks open only on certain pages?

Home Forums Support Can I make hooks open only on certain pages?

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #64776
    George

    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!

    #64848
    Tom
    Lead Developer
    Lead Developer

    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; ?>
    #65134
    George

    Great, the code worked excellently. Thanks a ton!

    #65246
    Tom
    Lead Developer
    Lead Developer
    #70009
    Carlos Paramio

    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

    #70189
    Tom
    Lead Developer
    Lead Developer

    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; ?>
    #70255
    Carlos Paramio

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

    #70429
    Tom
    Lead Developer
    Lead Developer
    #71532
    Joseph

    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>

    #71533
    Joseph

    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!

    #71535
    Tom
    Lead Developer
    Lead Developer

    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%;
          }
    }
    #305338
    heliosmp

    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.

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.