GP Hooks has been replaced by our Elements module. Learn more about the hook system in Elements here.

Using Hooks with Conditional Tags

Our Hooks add-on allows us to “hook” our own custom code into various areas of the theme without changing core files.

By default, the content added in hooks will show up on all pages and posts.

We can also use Conditional Tags to show hooks on specific pages.

We will need to Execute PHP for the conditional tags to work.

Here are some common examples:

Blog/Posts Page

<?php if ( is_home() ) : ?>
    This Content will ONLY show on the blog/posts page
<?php endif; ?>
<?php if ( ! is_home() ) : ?>
    This content is EXCLUDED from the blog/posts page
<?php endif; ?>

More info on The Main Page.

Static Front Page

<?php if ( is_front_page() ) : ?>
    This Content will ONLY show on the static front page
<?php endif; ?>
<?php if ( ! is_front_page() ) : ?>
    This content is EXCLUDED from the static front page
<?php endif; ?>

More info on The Front Page.

Latest Posts as Home page

<?php if ( is_front_page() && is_home() ) : ?>
    This Content will ONLY show on the latest post page
<?php endif; ?>
<?php if ( ! is_front_page() && ! is_home() ) : ?>
    This content is EXCLUDED from the latest post page
<?php endif; ?>

More info on The Blog Page.

Single Posts

<?php if ( is_single() ) : ?>
    This Content will ONLY show in single posts
<?php endif; ?>
<?php if ( ! is_single() ) : ?>
    This content is EXCLUDED from single posts
<?php endif; ?>

See more info on A Single Post Page.

Static Pages

<?php if ( is_page() ) : ?>
    This Content will ONLY show in static pages
<?php endif; ?>
<?php if ( ! is_page() ) : ?>
    This content is EXCLUDED from static pages
<?php endif; ?>

See more info on A PAGE Page.