WordPress Development: Theme Functions

Posted on July 10th, 2009

WordPress Development

When developing a WordPress theme, there are a number of things you should add to make it more standardized. As many WordPress plugins rely on certain functions to exist within a theme, it is important that you add these to your theme, so as to ensure these plugins will work correctly. As well, there are functions designed to make the development of your theme easier, which we’ll be going over.

Template Hooks

In a WordPress theme, there are two actions which you should add to your theme. As mentioned earlier, many plugins depend on these hook existing in the theme and will break if they don’t. These hooks in question are the wp_head and wp_footer hooks, which exist in the head of the document and right before the end of the body (respectively).

Implementing these hooks is simple. Simply place the following on a new line before your </head>:

<?php wp_head(); ?>

Then place the following before your </body>:

<?php wp_footer(); ?>

Helpful Functions

WordPress provides many functions for theme developers to use to simply the coding of their theme. A quick rule of thumb before we get into these functions: if a function name if prepended by get_ it means that function will return the result, it’s non-prepended counterpart will echo the result. Here’s a sampling of the functions WordPress includes for themes.

get_header() – Includes the theme’s header.php
get_sidebar() – Includes the theme’s sidebar.php
get_footer() – Includes the theme’s footer.php
bloginfo() – Get the associated result for the provided parameter and outputs it to the browser
get_bloginfo() – Like bloginfo(), but returns the result instead
get_option() – Returns the value of the option name provided in the parameter from the wp_options table
get_search_form() – Includes the theme’s searchform.php file
next_posts_link() – Outputs a link to the previous page of posts. Learn more
previous_posts_link() – Outputs a link to the next page of posts. See next_posts_link() for parameters
Conditional Tags – Checks if a condition is true or false. Returns boolean. Learn more

This list is just a sample of the various functions available for use in themes. To learn more about other available tags, please see the WordPress Codex.

What do you think?Comments Off

Posted in Development | | | Digg This | del.icio.us | Technorati


Related Topics:
WordPress Development: Plugin Theme Functions
WordPress Development: The Loop
WordPress Development: Theme Basics
WordPress Development: Widget-Enabled Sidebars
WordPress Development: Automatic Feed Links

RSS feed

Comments

No comments yet.

Sorry, the comment form is closed at this time.

© 2007 BlueFur Hosting | Privacy Policy
Theme by Unique Blog Designs