My tips for this week will help you become a better WordPress developer and designer. The WordPress Codex is your first stop to learn more about WordPress functions. To dig deeper than what the Codex can offer, use Grep to locate functions inside WordPress so you can see exactly how they work.
If you are a WordPress developer, a WordPress site designer, or just want to get a better understanding of how WordPress themes work, you should get very familiar with the WordPress Codex. It is a one-stop resource for articles and technical documents about WordPress, themes, and plugins. If WordPress does it, there is at least a primer about the topic on the Codex.
If you build WordPress sites, do yourself a favor and read at least one article a day on the Codex. The knowledge you gain will quickly translate into better sites.
Here are a few gems to get you started:
- Stepping Into Templates – A great article about how theme template files are used.
- The Loop in Action – Detailed article about The Loop, how it works, and how to modify it.
- Template Hierarchy – What each of a theme’s template files are used for and when they are used.
- Template Tags – These functions are used to add content to templates.
Grep is incredibly simple, but what it offers is priceless. This tool allows me to search through tens or hundreds of thousands of lines of code in seconds.
Why would I want to search through all this code you might wonder. While the documentation found in the Codex is great, over my time working with WordPress, I found that the Codex can often be out-of-date, resulting in missing or invalid documentation about different functions. In addition, some functions are so complex, that documentation simply can’t adequately describe how to use the function. So, I use Grep to quickly locate where function declarations are so I can read exactly how the function works.
For example, imagine that I want to read up on how the
the_content works. I can use the following Grep command from inside the WordPress file directory:
grep -r 'function the_content(' *
This will quickly tell me that the function declaration is in the
wp-includes/post-template.php file. Looking at the function declaration, I can quickly see that another function,
get_the_content, does most of the work for this function and that the content is filtered through the
the_content filter before being printed. This information could greatly help me now that I know it.
I go into more detail on using Grep in a post I did on my personal blog a while back. Read my grep – Why I Love Linux post for more depth on the topic.
As for getting Grep on your system, all Apple and Linux OS’s will already have Grep. This means that your Linux-based hosting environments will have the grep command available for use via an SSH connection. As for Windows, you can find details on getting Grep here.