It was a long run, but we finally got to the last part of the series. I hope it was a fun and educational journey and you enjoyed the series as much as I did.
The first part was about introducing Conditional Tags. In this part, we learned about what Conditional Tags are, how important they are for WordPress theme and plugin developers, and how to use Conditional Tags in WordPress development. In addition, I came up with five different example cases in which Conditional Tags come in handy.
In the following five tutorials, we went through 65 Conditional Tags in total. There were 66 documented Conditional Tags when I started and finished writing this series. One of them was a deprecated function (
is_plugin_page()), so I wrote about 65 Conditional Tags, with descriptions, parameters and examples for some of them.
In the second part, we learned about the following Conditional Tags:
In the third part, we went through these Conditional Tags:
In the fourth part, we checked out the following:
In the fifth part, we examined these ones:
And in the sixth part, we studied the following Conditional Tags:
In this "bonus chapter", we're going to look at three plugins that focus on using Conditional Tags. These plugins can be very, very powerful when you need them and if you use them right!
Downloaded nearly a million times and with a star rating of 4.3, Widget Logic is by far the most popular plugin that makes use of Conditional Tags. And it's not surprising that it's so popular, because it virtually keeps us from having to create separate sidebars for separate occasions.
The logic of this plugin is simple: It places a little input under each widget in the Widgets page of your admin panel, so that you can type in Conditional Tags, just like when you write in your
if statements. Be careful though: This plugin uses
EVAL functions, which means that anyone who has access to Widget Logic inputs can write any kind of PHP code. Any kind. Be warned.
wp_enqueue_script() function. It basically takes all the enqueued scripts and lets you add Conditional Tags to wrap the scripts and load them conditionally. This script also uses
EVAL functions to work, so be careful.
Remember the example we looked at for the
is_feed() Conditional Tag? This plugin extends it to 19 Conditional Tags in total, including our example. Here's the list of Conditional Tags the plugin supports:
The usage is just like any other shortcode: Put the Conditional Tag in square brackets and pass the parameters of the Conditional Tag as shortcode parameters. The plugin also has "else" shortcodes that you can use inside the listed shortcodes.
As I said, this series was a long but fun journey for me. And I hoped you enjoyed it as much as I did.
If you have any questions, contributions or comments, shoot them below in the comments. And if you liked the series, don't forget to share it with your friends!