Do more with your WordPress using the function reference - gHacks Tech News

Do more with your WordPress using the function reference

If you've been developing themes, or taking a go at modifying your own, chances are you've run into the WordPress Template Tags page. This part of the WordPress Codex lists numerous functions you can use to customize your themes quickly and easily, even if you're just stepping into the wonderful world of modifying your blog, it's worth a look.

Among other things, it allows you to add category lists, show comment ID-s, show comment authors, display next image links, add a dropdown box of categories anywhere, useful, and basically "drag and drop".

There is however another great WordPress reference which is a bit more obscure, but also contains a huge load of functions for some other tasks you might have around your site. The WordPress Function Reference section of the codex lists at least 250-300 functions for pages, authors, plugin usage, comments, users, etc, in short, encompassing the whole blog platform, as opposed to more blog post oriented functions in the Template Tags section.

The page is chock full of things like "in_category()", which if passed a post ID and a category, will tell you if that post is in the category or not. Great if you want to display category specific content on your main page for example. It also gives you real power, with functions like "wp_insert_post()", which you can use to insert posts "manually", by passing an array of info to the function. Similarly you can use wp_insert_user() to add a user, with the parameters you want. Very useful for creating some custom sign up forms, custom permissions and so on.

What I've come to appreciate while using these functions is how very well WordPress is thought out. I sort of knew this 3 years ago when I started, but when I began to use these functions I realized why. For example, wp_insert_user() will insert a new user, and will return the new user's ID. It returns 0 if there is an error, but more importantly, if you pass an existing user's ID, it will update that user, instead of creating a new one. There is a separate wp_update_user() function, but the action they perform is so close, it's very handy that inserting a user is so flexible.

If you're just jumping into these functions you'll find them quite easy to use, while giving you a lot of control. If you're an experienced PHP programmer you'll find you'll program less, and you'll also appreciate the work going into WordPress a lot more!

Summary
Do more with your WordPress using the function reference
Article Name
Do more with your WordPress using the function reference
Description
Provides information about the function reference in WordPress including how to use it.
Author
Advertisement

We need your help

Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.

If you like our content, and would like to help, please consider making a contribution:


Previous Post: «
Next Post: »

Comments

  1. Alex said on August 26, 2009 at 10:31 am
    Reply

    Very nice post. I never tought there were so many wp template tag choises

  2. Daniel Pataki said on August 30, 2009 at 8:22 pm
    Reply

    Yes, I honestly don’t know why they don’t make this more apparent. I can see the distinction between template tags and functions, but still, I think they could “market” this a bit better.

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

Please note that your comment may not appear immediately after you post it.