Skip links

3 Great Uses for Genesis Simple Hooks Plugin

If you’ve poked around my site at all, it’s no secret: I’m a big fan of the Genesis Framework for WordPress. After getting a fresh install up and running, one of the first plugins I download is Genesis Simple Hooks, which is, as the name suggests, an easy way to tap into the Genesis Framework and modify the output with your own bits of code.

Now, some of what you could accomplish with Simple Hooks could also just be written into your functions.php file, but here’s why I prefer Simple Hooks: Miss one single quote or semi-colon in functions.php and you can kill your entire site. You’ll have to re-upload a fresh copy of functions.php via FTP to restore your site to its buttery goodness. Simple Hooks, on the other hand, is a little more forgiving. A syntax error in your code can result in an ugly error, but it won’t sink the ship.

Of course, there are instances when it’s better to use functions.php (like writing actual functions!), but that’s not the main focus of this post. So getting back to the topic at hand – What are some easy things you can do with Simple Hooks?

**Disclaimer** I’m no code pro. Everything I’ve learned about Genesis and WordPress has been the result of bootstrapping my way around the web and support forums. Below are examples that have worked for me, but I would welcome the input of more advanced developers to suggest more elegant ways of doing things!

3 Things you can do with Genesis Simple Hooks

Number 1: Install Google Analytics.

Of course there are plugins out there that do this for you, but it’s such a simple snippet of code, why use one more plugin when you can simplify?

From your WordPress Admin dashboard go to Genesis > Simple Hooks and use a quick Ctrl + F to search for the genesis_after hook, located in the Document Hooks section.

Anything you put in this section will execute on the page immediately before the closing </body> tag, which is where I like to stash my Google Analytics. Drop in the script provided from your Google Analytics account and click Save Changes. Voila! Tracking is installed throughout your site!

Number 2: Place an ad after the first post on your blog archive page.

Oh how I love conditional statements! WordPress is chalk full of built-in functional references that you can use to know “where” you are in the code. Am I on a page? Do this! Am I on a post? Do that!

You can use Simple Hooks to insert these little “where am I” checks into The Loop and modify your output accordingly. For instance, let’s say you want to show a single ad only after your first post on an archive page.

Get back into your Simple Hooks settings and do a search for genesis_after_post_content. It’s in the Post/Page Hooks section.

What we’re doing here is using a conditional statement to check two things:

We’re on the first post in the loop ($wp_query->current_post == 0) and (&&)

We’re on an archive page (is_archive)

If both those statements ring true, we want to show our ad, which I’ve wrapped in it’s on CSS class so we can style. Note that I’ve checked Execute PHP since I’m including PHP code. Here’s the code in the screenshot above in case you’d like to use it:

Next, let’s head over to our Genesis Simple Hooks settings and find the genesis_before_post_content hook in the Post/Page Hooks section.

Let’s unhook genesis_post_info() since we don’t want any of the default post info to print. Also, we’re only using our custom Location field on posts, not pages, so we’ll use a conditional statement to figure out where we are.

Lastly, don’t forget to check the Execute PHP box since we’re including PHP in our hook! Voila! Now our location and date will print on single post pages, between the title and the content.

Wrap-up

Alright, so there’s a few ways you can use Genesis Simple Hooks to customize your website. Don’t forget to check the plugin forum or the StudioPress forums and search for other ways you can use Simple Hooks. Have a question or want to suggest a better way to accomplish the above examples? Leave a comment!

Comments

Great article. There are some cool features in Genesis that can simplify your code. For example, when working with custom fields, you can skip the part where you get the post ID and such by using genesis_custom_field. So your code looks like:

Interesting. I have been using Simple Hooks for a while but with the latest Genesis I find it easier to simply insert the Analytics code in the footer Theme Settings page. The Simple Edits plugins fills out my other needs. Do you think Simple Hooks should be used instead of Simple Edits? Sometimes I think we have a boatload of plugins installed…..

Hi Carrie,
Wow, love your posts/info. Very helpful.
Hey, I’m trying to do the same thing for post_date as you’ve shown for location– that is to have the date appear for only one category of posts.
I’ve unhooked genesis_post_info() from the genesis_post_content hook (because I don’t want 90% of it! And I’ve re-located the author to another location– for all posts).

I think I could use most of your code above, but I’m not quite sure how to “re-word” it for the post date. And would it make a difference if I put instruction for this in Simple Hooks, or (with code adjusted) do it in my functions.php? I feel like I’m setting myself up for a conflict by removing, then adding the same function on the same hook!

If you do it in Simple Hooks, just the conditional code and the print statement will work (as in the example above). If you decided to add it to your functions.php, you’ll need to wrap that code in a function (a la that StudioPress link).

Hi Carrie, Thanks so much for your quick response!
Unfortunately, WP didn’t like that — I guess– because I unhooked the post_info at the genesis_before_post_content hook and maybe Genesis now can’t grab the [post-date] because there’s no post_info from which to grab it??

Should I:
add the post_info first up at genesis_after_post_title hook where I want it, then follow with your code? Just not sure I know the syntax to do that in simple hooks.

??

Or should I scrap this and leave the post_info intact (in Simple Hooks) and just go to my functions.php and try a conditional filter:

Ah, okay. I missed your before content / after content bit in your first comment.

If you take the Simple Hooks route, you’ll want to Unhook genesis_post_info() from the genesis_before_post_content Hook. THEN you add in your conditional statement in the genesis_after_post_content Hook.

If you go the functions.php route, do the code above, but first you’ll need to unhook it:

You’ve been so generous with your time (and blog comments space!).
To sum up, I think I mistakenly thought of post_info as having or being a short code when it is it is the parts of it that do. Secondly, if I UNhook the post_info from Simple Hooks default position, and want to REplace it at a position that occurs BEFORE that: genesis_after_post_title, is there a one-line action or function IN SIMPLE HOOKS that will do that trick? And does it matter if I’m placing it at a point BEFORE the default?

Thanks so much in advance. I’ll let you off the ‘hook’ after this!
; )
In my fourth full day of trying to solve this one problem,
Lorin

As long as something happens within the loop (i.e. post_info) you can move it/access it anywhere within the loop. You just can’t access it OUTSIDE the loop. So you can safely put it after the post title or after the post content – it’s alllll in the loop.

As for the magic short codes (here’s a list), you can pop them right in to Simple Hooks! Just be sure you check the “Execute Shortcodes on this hook” option. You can let it fly solo, but in your case you’re needing the conditional PHP statement, so be sure you’re also checking the “Execute PHP” option.

Great info and tips in this post! I’m a big fan of this plugin. I was just trying to put some PHP into a hook and was worried that it would break my site if there were any syntax errors as is the case with custom functions. Good to hear that this is more forgiving.

Got any ideas on how I can use hooks to disable commenting for a certain category? I’m using a Genesis child theme that pulls portfolio items onto the portfolio page via a specific category in the blog. We’re going to utilize the portfolio page as a “meet the staff” page, so I’ve got the category “our staff” and would like to just disable the comments for just this particular category so that, when adding a new staff member, my client doesn’t have to remember to disable comments on those particular posts.

Hey cool Carrie, you just came up third from the top when I googled “how to use genesis simple edits plugin” just now. And, thanks to you, I’m using the Simple Hooks plugin instead. It’s great! This is a very helpful post–especially the comments exchanges… Thank you.

Carrie,
Great stuffs you’ve got here with your Simple Hooks plugin, I’m using it in my new site.
I was searching for the code snippet that could sort out my pain when i found you on the search results..
I am working on a new site, using genesis + magazine ver2.1. With “Comments” enabled for both “Page” and “Post” and codes for email opt-in form(let’s name this newsletter) insert in “genesis_after_post_content Hook”

I was going to add a new “page” using magazine’s “landing page” .

I create the short sales copy within GetResponse’s webform builder(let call this bonus), paste the code to the new page’s “html” text box and hit publish. And the following happens:

1) Title shows up: landing-bonus

2) The “enter email here” box, “submit button” and “submit” text are all over the place

3) The previous “opt-in” form (newsletter) below all “content” after post/page shows up.

4) Comment box shows up

My question, I will use “landing” in all future landing pages, but how to remove:

a)title
b)”newsletter” opt-in form
c)”comment box”

from showing up at the magazine child theme “landing page”?

How to insert the webform code into magazine’s landing page so that the email box, submit button, submit button’s text shows up the right way it should be?

Hey Joshua,
Your questions are a little more in-depth than I can get into off the top of my head in a comment. But I think you might want to edit the landing page template directly to get your desired output since you’re going to re-use it with the same format.

My Lynda.com Courses

I drop affiliate link bombs all over this site and may earn a commission if you purchase through my links. So, if you like my content and learn about a cool product here, click a link and help a sister out. All of that said, I try really hard to be the opposite of smarmy when I use affiliate links. To learn more, check this out.