Another Catalyst Theme Tip: Email Signups

chrislema-face

catalyst-theme-tip-emailEvery couple of days I see a site that inspires me to think about a new design. I’m the kind of guy that (left to my own desires) would change his theme every week. But my site goals are readability and the development of trust, and you can’t do that if you keep changing what your site looks like and where you can find content.

But there’s another reason why I don’t change my theme framework – and that’s because I find that almost anything I want to do can be done using the Catalyst Theme, which I run here on chrislema.com. Don’t get me wrong – I love all the other frameworks that I write about and I use them all on projects too. But every time I have a little idea, Catalyst seems to be ready for me to test it out.

But first…a word about my Hosting Provider

Before I get into this bit of code, I want to remark again how awesome it is to be hosted on WP Engine. This time, I’ll just tell you that before I learned of their staging area, I’d never had a host provide me with something similar. In fact, on many hosting solutions, I would often buy another domain and set up another account, just to play with code on the same environment.

I could go long into why local testing only covers part of the dynamics and why testing your changes on the actual environment is critical, but that’s for another time. Instead let me just say that I was able to test all all of these tweaks on chrislema.com and that is one more reason I love WP Engine.

Today’s Catalyst Tip – Email Sign Ups

So, if you’re reading this, you can see that I’ve placed an email sign up on the right side, in an orange box. That was really simple and required work at all. But here are the steps:

  1. Log into MailChimp (or your hosting provider)
  2. Navigate to Lists
  3. Click on the gear and pick “Forms”
  4. Then look for the options under “For your web site”
  5. Grab Signup form embed code
  6. In WordPress go to Appearance > Widgets and add a text widget
  7. Place your embed code there and save

If I had to summarize it, I’d say, “copy the embed code for your signup form from your mail provider and paste it into the html/text widget” and you’d be set.

But that’s not the tip I want to walk you thru. That orange box signup form has been there for a while. No, instead, I want to talk to you about the other one, below, just above the comments, in the black box. See it down there? Go ahead, scroll a bit and check it out – I’ll still be here when you get back.

Placing a Sign Up Below Single Posts

The great thing about Catalyst is that it understands you may need to do some complex things but it keeps them simple. So let’s get started.

The first thing to note is that I am going to use a “hook box.” If you’ve never heard of a hook box, it’s the Catalyst way of saying, I’m going to attach some code somewhere on the site, basing it’s location on an existing “hook.” Catalyst has created a set of hooks that helps you in this case.

Step One: Create a Custom Hook Box

You create a custom hook by going to the Catalyst > Advanced Options > Custom Hook Boxes. Now, you click on the Add Button and it gives you a blank hook box. Go with me here, even if you’re not exactly clear on what we’re doing. I’ll explain.

StepOneCatalystHookBox

In the name, put something like “emailform” and in the open box below, let’s add our code.

<div>Did you like this post? If so,
you might like getting my daily post
via email -
<a href="link-to-email-form-here">
directly in your inbox.</a></div>

That is the code that you’re planning on adding to your site. It’s a regular

with a link to your form. [Hint: you can get the link to your form by creating a signup form in MailChimp].

Step Two: Tie the Hook Box to a Hook

There’s a Hook drop down on the form. Catalyst provides a huge list of hooks. Not that you need it, but if you want, you can see the whole map of hooks right here. What we’re going to do is tie it to the one we care about, which comes after the post (since we want it after a post and before the comments).

Pick: Catalyst_Hook_After_Post – this is the one you want. But also make the Priority: 1. This puts it first out of anything that may be using this hook.

Once you do this, you’ll see that it shows up at the bottom of the post before the comments. Yeah!

But wait? It also is showing up between excerpts on any archive page. And we don’t want that!

Step Three: Conditionally Show it

Don’t worry. We’re going to use a conditional to only show it when we’re actually reading an article. When we’re reading an article, the view we’re looking at is often called the “single page” because we’re not looking at a list of posts. So WordPress itself has a filter for that, and Catalyst will let us use it. Here it is:

php if ( is_single() )  { ?>

That code says, “hey, only do what’s next if we’re looking at a single page.” So that’s what we have to do – wrap our earlier code with this conditional statement. And when your code is complete, you need to end the conditional reference. So that means you should go out later and add this code at the bottom.

php } ?>

What we’ve done is limit when the hook box displays anything. Here’s what it looks like live on my site.

mailformresults

Conclusion

Of course you can do more and go further from here. You can style the div, the link, and even the text. But the trick for me was using a hook box effectively. And Catalyst makes it really easy.

I don’t have the data yet on how effective it is to have the sign up in both places but the last couple days it’s gone well. If you do it, come back and let me know how it went.

About Chris Lema

Chris Lema has been working with WordPress since 2005. Over the years he's been a blogger, a speaker at WordCamps, a coach for WordPress product companies, and the founder of the conference for WordPress business owners, called CaboPress. Today he's the VP of Products at Liquid Web, where he manages the world's first managed platform for WooCommerce stores.

Chris Lema

Chris Lema has been working with WordPress since 2005. Over the years he's been a blogger, a speaker at WordCamps, a coach for WordPress product companies, and the founder of the conference for WordPress business owners, called CaboPress. Today he's the VP of Products at Liquid Web, where he manages the world's first managed platform for WooCommerce stores.

Join more than 7,500 others

My posts. Your inbox. Beautiful.

Chris Lema Speaking

Do You Want To Pick My Brain?

Over the last few years, through private consulting, coaching, and using the pay-by-the-minute Clarity service, I've helped hundreds of folks like you solve their WordPress problems and overcome their technical challenges.

“In 18 minutes Chris was able to save me months of lost time and tens of thousands of dollars by directing me to the right technologies to create my course marketplace. The value was 100x what I paid.” — Josh

Have a question right now? Most of my Clarity calls last less than 20 minutes. Let's set up a call.