Searching the WordPress Codex Effectively: Part 1

Posted by Pixafy Team

If you’re new to WordPress lingo and would like to get started on editing WordPress templates, the one tool that will always be handy, whether you’re a novice or a WordPress master, is the WordPress Codex. It’s a quick reference to find not only all the code that most WordPress templates already have in them, but all the major functionality WordPress supports.

But if you’ve never searched the Codex before, or aren’t yet familiar with what WordPress can do, searching for something you’ve never seen before could be quite daunting. The great thing about WordPress though, is no matter how complicated the PHP looks at first to fresh eyes, what WordPress likes to do most is “get” things. Literally. This is common terminology within WordPress templates.

For example, if you need WordPress to get a date, you can try looking up “get date” in the codex.

You’ll likely find:

<?php get_the_date(); ?>

WordPress likes to “get” lots of stuff, like:

<?php get_permalink(); ?>

<?php get_the_author(); ?>

<?php get_the_title(); ?>

WordPress also likes to be plain at times and things like below work as well:

<?php the_permalink(); ?>

<?php the_author(); ?>

<?php the_title(); ?>

Although these snippets look very similar to each other and they should perform the same function, it’s a matter of whether you’re in a page or a post, whether you’re inside or outside the loop, and also the options you have for customization. That explanation will come in a future blog post.

For now, I can tell you that one major difference between using “get” versus “the”, is “get” will retrieve the information you need, but it does not know how to spit that information out for you. It’s like a puppy. You can tell the puppy to get the stick behind the couch, but once the furball’s gone behind there and has the stick in his mouth – well he might just hang out there for a while. Fido does not know that you need to see the stick; all he knows is that you wanted him to get it.

WordPress’  “get” functionality works the same. To show the information that was retrieved, you would use the same line of PHP, except this time we’d add “echo” to it:

<?php echo get_the_permalink(); ?>

<?php echo get_the_title(); ?>

Echo‘s a common PHP operation that tells WordPress to spit out the information that has been fetched so that you can see it.

Now that we know how to get some decent search results from the Codex, what happens if you have arrived on a page that seemed like the right direction only to realize that it wasn’t quite what you were looking for? Don’t hit the back button just yet.

The Codex’s related links on the bottom of these pages are usually very faithful in giving you other functionality that is similar to the page you’re already on. So if you’re on the_date, but realized maybe you wanted get_the_date, odds are there’s a handy link on the bottom of the page in the Related section.

Last but not least, if you find that the Codex is not giving you what you need by using “get” or “the” in addition to what you’re looking to retrieve via searchbar, browsing through WordPress’  Template Tags or Function Reference pages might just have your answer without having to use the search bar at all.

Happy searching!

Is there something cool you learned from the Codex? Share with us in the comments!