Using Hooks In Woo Themes

Unlike the Genesis and Thesis hook plugins, the Woo Hook Manager in the Canvas theme doesn’t enable you to execute PHP or Javascript code.

So whats the solution?

You’ll need to add the code in your themes templates files or better still, write a custom function which you can also use with conditional tags.

Lets take a look at some examples of code you can add to your child themes functions.php file to display banners, ads or pretty much anything else in different hook locations your Woo theme offers.

Display In WordPress Footer Based On Conditions

This code will work in any theme because it uses a WordPress hook and not a theme specific hook.

Change the conditional tag to whatever you like.

In the above example i’ve used a conditional tag for pages and added the page i.d of 100 which you will change to your own.

Execute Code In Any Theme Head Section

If you simply want to display content using the wp_head hook in WordPress, you can add this code to your child themes functions.php file.

This code will work with any theme.

You can change the WordPress hook wp_head to any other hook including theme specific hooks.

Note: Using the wp_head hook to load Javascript requires the files to be enqueued before the wp_head action hook.

Woo Specific Hooks

This code will output your content after the posts content in a Woo theme only.

You can easily change the Woo ‘woo_post_after’ hook to another.

The below example will output your HTML before the posts content.

But Wait! There’s a Problem.

The code will also output on archives pages like you blog or homepage. So how do we fix that?

We add a conditional tag so it only displays on single posts and/or single pages. Not on archive pages.

Add Content After All Single Posts

This code displays after all posts on single posts only.

Add Content Before All Single Posts

This code displays before all page content on pages only including archive pages.

These are some examples which you can use in a Woo theme. The code snippets using the WordPress wp_head or wp_footer action hooks can be used in any theme.

Hook Reference Map

Here’s a complete list of Woo hooks displayed in a visual map.


Comments

10 responses to “Using Hooks In Woo Themes”

  1. Hi Brad,

    Is there a way to modify this so that it shows after the first post only?
    Thanks,

    Scott
    [code]
    add_action(‘woo_post_after’, ‘wpsites_display_content_post_after’);
    function wpsites_display_content_post_after() {
    echo ‘Display Content Site Wide Post After Hook’;
    };
    [/code]

    1. Brad Dalton Avatar
      Brad Dalton

      Shows after the 1st post on archive pages or home page or?

      1. Hi Brad,

        What I am trying to do is add content after the first and second posts on the archive pages.

        Sorry for the confusion,

        Scott

  2. Cecily Avatar

    Hi Brad, being that Canvas doesnt allow us to execute PHP or Javascript code, how would I relocate the post titles and meta data above the Featured Image? I think its strange that these items are reversed and most of my clients want their posts to display this way. Any hints would be appreciated!

    1. Brad Dalton Avatar
      Brad Dalton

      I think the best solution would be to use something like what you can use with Genesis like a remove_action and then add_action.

      You just need to find the correct hook and function names which isn’t that easy in Canvas as there’s over 100 files.

      Another solution is to copy over the files to your child theme and edit theme there but that’s really not the best method.

      I would ask this question on the Woo Community forums and see if you get answer but i don’t know the exact action names and would need to look in the files to find them.

  3. Hi, Is there a code snippet that will display the hooked content (like a slider) on only the front page? Thanks

    1. Brad Dalton Avatar
      Brad Dalton

      Add the [code]is_front_page()[/code] conditional tag after the function.

      [code]
      function slider_front_page() {
      if (is_front_page() && function_exists( ‘soliloquy_slider’ ) ) {
      soliloquy_slider( ’88’ );
      }
      }
      add_action(‘woo_header_inside’, ‘slider_front_page’);
      [/code]

  4. Bradley Charbonneau Avatar
    Bradley Charbonneau

    Brad, you’re a rockstar!

    Dear WP Sites readers, I asked a quickie question in a comment the other day to Brad and not only did he answer it, he wrote up a whole post pummeling the question with several solutions. That is going above and beyond.

    Big brownie points in my book, Brad. How can I return the favor? IMHO, the WordPress world is one of cooperation and it’s been working great for me for years. Let me know if you need anything.

    Best regards,

    Bradley

    1. hahaha! Its because you’ve got a cool name Bradley! I really do appreciate it when my readers leave comments and tell me what they need because it gives me ideas on what to write about. Keep them coming because i need to offer a diverse range of solutions and don’t want to focus on one specific theme. Cheers

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.