I want to preface this post by saying I'm in awe of both the quantity and quality of plugins that people have developed for bloggers to use for free—the WordPress directory alone has almost 8,000. I use a handful of them myself (and have tried out many, many more). Some add extra functionality to the people visiting the blog, while others simply help the bloggers do what they need to do faster or more easily. Thesis OpenHook fits into the latter category.
In my earlier post, What Are Hooks and How Do You Use Them?, I explained one of the key principles of Thesis, which is that when you want to make changes to the theme, you don't actually edit the core files. Instead, you write new functions using the PHP coding language and insert them into placeholders (hooks) that have been predefined within the theme. This approach has a number of advantages, however you can't really benefit from them if you don't know how to write PHP functions yourself.
That's where OpenHook comes in. You still need to be able to write code, but in many cases you only need HTML, a language many more people are familiar with than PHP (although you can also use PHP as well as JavaScript and XHTML). Then you put that code into a box within the OpenHook interface and it does the back-end PHP work to insert your code into the appropriate hook.
Sounds great, right? And, in fact, I've tried it and it works great. So this isn't at all a criticism of the plugin. However, unless you're just a complete code-a-phobe, I would recommend not using OpenHook because I think it insulates you from what it is you're actually doing to customize your site. If you're going to the trouble of writing any kind of code, you might as well learn how to write all of it. And, frankly, the code that PHP is doing for you is pretty fast to learn and you can easily copy and paste it and just change the function name to use it over and over again.
The difference between coding in OpenHook vs. custom_functions.php
In that earlier post about hooks, I added a blue rectangle to the top of the page to illustrate where that hook was. If I were to do this in OpenHook, I would add this code into the Before HTML box:

If I were to put it directly into the custom_functions.php file, it would look like this:
?>
<div style="height: 20px; background: url('http://www.ektest.com/default2/images/blue_rectangle.jpg') repeat-x left top;"></div>
<?php
}
add_action('thesis_hook_before_html','blue_rectangle');
At first glance, that may look like it's a lot more complicated. But it's really not (trust
me... :) It's just adding a few more lines to the original code to define the function, identify the code as HTML instead of PHP, and then add the function into the hook. And you'll be reusing these same lines over and over, just changing the name of the function and what hook it goes in.
That brings me to another reason why I don't recommend using OpenHook. When you're first starting to use Thesis, you'll probably be going to the forums and other resources a lot to try to find code to do what you want it to do. In most cases, those places are going to give you the full code that should go in custom_functions.php. If you copy and paste it in full in OpenHook, it's not going to work. So then you have to figure out which code to strip out, which can cause its own errors.
Finally, using OpenHook doesn't mean you'll never have to learn PHP. As soon as you want to use a conditional statement—for example, if you want to add content on some pages but not others—you're going to need to learn some PHP to do that. And if you want to add multiple functions into the same hook, you can't do that in OH, so you'd have to write them and add it in the file anyway.
So, for all those reasons, I just think it makes sense that you keep all of your custom code together from the get-go, which will force you to learn how to use it faster (and therefore help you get more creative with your theme faster.)
NOW, having made what I feel is a pretty strong case against using OpenHook, I think there is one situation where it can be very helpful, even if you're a very experienced coder. Because each time you want to make a minor change to a function, you have to reopen the file, make the change, save it, and upload it via FTP back to your server to see its effect. Instead, you could use OpenHook as a way to test minor changes to your code, since you can make the change and just click the Save button to see what happens. This has the added advantage of not breaking your custom_functions file if you make an error. Then, once you've got the code working the way you want, you could move it to the file and add the few extra lines of code you need to define and display it.
One last thing
If I haven't convinced you and you still want to use OpenHook, that's fine. But I often see posts on the forums from people who are having problems because they copied a style definition into the OpenHook box. That's never right. :) While you can add inline styles into a function, if you're actually defining a class or id in full, you do need to put that into your custom.css file. I'm talking about code that looks like this:
What about you? Are you an OpenHook aficionado? Am I missing some other advantages to it? Leave your comments below.
Sign up for the Thesis newsletter to get more great tips, delivered right to your Inbox!Posted in Blogging, Code Sample, My Two Cents, Social Media, Thesis



















{ 4 comments… read them below or add one }
Your perspective is helpful. I initially learned how to code custom functions before OpenHook was available. For just adding simple html, I think OpenHook is fantastic. In fact, after I started using it I let myself forget how to do the custom functions (which is why I ended up on your site). Your example makes me slightly more willing to open up my custom functions again… Thanks.
That’s kind of what I was thinking shortly after I tried it out—that it would become a crutch and I’d have trouble with functions later. If you have any questions about any functions you’re working on, don’t hesitate to send them along as well!
Interesting… I love openhook. Sure it’s kind of lazy but it offers you little check boxes to turn things off and on. Chris Pearson should take cues from this and build it into Thesis, and then have it auto update the custom_functions file. Just my 2 cents.
Thanks — I appreciate the other perspective!
{ 1 trackback }