WordPress: Conditional Call to Action after a Post Based on Category

By
Updated February 16, 2016
No Comments
5

WordPress: Conditional Call to Action after a Post Based on Category


Tim Brown

Tim Brown is the owner of Hook Agency, and strategic marketer focused primarily on driving traffic and leads for small businesses and construction companies.

After reading many posts on HubSpot, I was always appreciative that their call to actions at the end of blog posts were specific to what I just read. When I finished a post about social media, there would be a call to action: “Enter your e-mail now, for a free download of ’99 quick tips for skyrocketing your social media engagement’ or if I finished a post about WordPress there would be a call to action: “Sign up now to get a WordPress Snippet a day for better development.”

So this has all kinds of applications –

Figure out what makes sense for your situation

Getting specific is important – so for you marketing minded people who code – you can use this WordPress snippet to create a conditional call to action after a post based on the category of the post the visitor is reading.


<?php if (in_category('marketing')) ?>

<img src="https://placehold.it/650x350?text=Marketing+Blog+Call+To+Action">

<?php elseif (in_category('web-design')) : ?>

<img src="https://placehold.it/650x350?text=Web+Design+Call+To+Action">

<?php elseif (in_category('web-development')) : ?>

<img src="https://placehold.it/650x350?text=Web+Development+To+Action">

<?php else : ?>

<?php endif; ?>

An example of this is right below for my WordPress development category. Since this post is in that category, I am showing a call to action for my forthcoming e-book “WordPress Development for Noobs.”

  •  
  •  
  •  
  •  

Related Posts


Tim Brown

Tim Brown is the owner of Hook Agency, and strategic marketer focused primarily on driving traffic and leads for small businesses and construction companies.

Download my E-book "WordPress Development for Noobs" for free right now:

  • This field is for validation purposes and should be left unchanged.
Only the best of web design & marketing

Leave a Reply

Be the First to Comment!

Notify of
avatar

Ready to Get Started?

Get a free consultation now