Jason G. Designs

WordPress Themes, Design Tutorials, Linux Themes and more…

How to Bring Your WordPress Theme up to Current Standards

4. To Change bloginfo('template_directory') to get_template_directory_uri() (recommended)

This one was a recommendation by the Theme Check plugin, rather than a requirement. Even though there is no mention in the WordPress Codex of this specific function being deprecated in the future, many themes checked with Theme Check, including those submitted to the repository, are advised to use get_template_directory_uri instead. In my theme, a standalone theme, I did a search and replace in my header.php file and a theme options file and replaced (in bold):

<link rel="stylesheet" href="<?php bloginfo('template_directory') ?>/basic_reset.css" type="text/css" />

with

<link rel="stylesheet" href="<?php echo get_template_directory_uri() ?>/basic_reset.css" type="text/css" />

The way to add stylesheets shown above is deprecated. Use the enqueue method in functions.php below instead:

my_theme_enqueue_scripts() {
    wp_enqueue_style( 'reset', get_template_directory_uri() . '/basic_reset.css' );
    ...
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_scripts' );

According to the documentation, the get_template_directory_uri() function has to be echoed to display in the html.

If you are trying to locate a file relative to the top level in a child theme for example, remove the below from header.php:

<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory') ?>/basic_reset.css" type="text/css" />

and add the following to your child theme’s functions.php

my_childtheme_enqueue_scripts() {
    wp_enqueue_style( 'reset', get_stylesheet_directory_uri() . '/basic_reset.css' );
   ...
}
add_action( 'wp_enqueue_scripts', 'my_childtheme_enqueue_scripts' );

References: Function Reference/get template directory uri and Function Reference/get stylesheet directory uri.

5. To Change bloginfo('url') to home_url()

In my theme’s header, links to the blog’s home page and within a searchform needed to be replaced. Once again, bloginfo('url') may be deprecated in the future. In my theme the searchform code is within the header. If you have your searchform code in a separate file, don’t worry, Theme Check will find it.

In the header, find and replace the bolded part: <?php bloginfo('url'); ?> becomes <?php echo home_url(); ?>. In your searchform code, change it as so: <?php echo home_url('/'); ?>. The forward slash searches starting from your blog’s index page.

Reference: Function Reference/home url.

6. Additional recommendations found for my theme

In this section, I’ll briefly touch on these recommendations, as they are more options that may be provided as extras and conveniences to make things easier for blog administrators. In here, I will link to the reference page and a related tutorial.

add_custom_background– This WordPress 3.0 and up function adds the ability for blog owners to change background colors and images from within the theme. This speeds up development for themes that do not have options pages and for theme authors who do not know how to code them—definitely worthwile of considering. Add this in your functions.php file, preferably in your theme setup:

function my_theme_setup() {
    ...
    add_custom_background();
    ...
}

Backward Compatible version:

if ( function_exists('add_custom_background') ) {
add_custom_background();
}

Reference: Function Reference/add custom background
Tutorial: How to add Backwards Compatible WordPress 3.0 Features to Your Theme

add_custom_image_header– This WP 2.1+ function adds a custom header background—useful for “plug and play” header art or a custom logo. In my theme, custom logo and background imagery are handled by a theme options page. To add this capability is a little more involved, but not difficult, so I will provide the reference link, which has implementation details.

Reference: Function Reference/add custom image header

add_editor_style– This 3.0 and up function adds a stylesheet to the admin panel’s WYSIWYG post and page editor. A theme author creates a stylesheet to match the styling in the theme, so post authors have a more accurate view of their post without previewing.

Reference: Function Reference/add editor style
Tutorial: Change Editor Style In WordPress 3.0

Concluding

The issues found in my theme were certainly not an all inclusive list. In fact, your theme may already have updated code and features. As well, the Theme Check plugin may find several things that are not listed here. To keep your theme updated to WordPress’s Theme Directory standards, it is a good idea to install this plugin and then go hunting through the WordPress Codex for the fixes.

Has anyone used the Theme Check plugin for their themes or a downloaded theme? If you want to tell me about your experiences, post below. Thanks for reading.

Page: 1 2

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.