Feb 17, 2013

Guide to create the perfect WordPress theme

Filled under:

Guide to create the perfect WordPress theme

In ThemeShaper have created a guide for any developer who wants to create a Wordpress theme that meets all standards , so as to offer the best experience purely WordPress.

The guide is intended for developers to WordPress.com issues but is equally useful for any WordPress environment . And what I think is a tremendous interest in Spanish here it is ...


  1. All dynamic data must be escaped with esc_attr ()  before being delivered as HTML attributes 
  2. All dynamic urls must be escaped with  esc_url () .
  3. If the dynamic data are delivered as an attribute of an HTML script element must be escaped with  esc_js () .
  4. SQL queries containing dynamic data must be escaped with  $ WPDB-> prepare () .

  1. All text visible to the user should be prepared for translation.
  2. Avoid HTML into chains  of functions "gettext" whenever possible.
  3. The output of  sprintf ()  must be escaped  in the text strings used in the attributes.
  4. Locators printf ()  must be escaped  before inclusion in HTML attributes.
  5. Provides context  where needed.
  6. Avoid  anti-patterns  common.
Requests (queries)
  1. Direct SQL requests should be avoided. It is best to use one of the new objects  WP_Query  when possible.
  2. They can be used unlimited requests. Basically, this means that the parameter  posts_per_page  of  WP_Query  not be set to  -1 . Furthermore, the parameter  numberposts  of  get_posts ()  (and similar functions) must also have a positive value.
  3. The large requests be cached so  transient .
  4. Can not use  query_posts () . If you need to modify the main demand is better to use the filter  pre_get_posts . If you need to retrieve entries besides the main request is best to use the new object  WP_Query .
  5. Empty values ​​should not be passed to the argument   post__in  used to create a new  WP_Query . If you're using a dynamic value that should be empty is important to make sure it is empty before using the value in the request ( example ).
  6. Requests for terms to be checked in a facility that has 10,000 terms.
Submissions to the queue ( enqueues )
  1. All others including files must be compatible with the license  GPL .
  2. Make sure you use the appropriate protocol  to put others on hold files.
  3. Make sure you use the appropriate hooks  to put on hold scritpts and styles.
  1. Use the scripts included in the standard installation if any.
  2. Custom scripts should not be minimized.
  3. The scripts include third-party can not be minimized but should include the following:
  • The name of the library.
  • Version Number
  • License
  • URL
  1. The  main stylesheet  (style.css) it must hold for the action wp_enqueue_scripts .
  2. Never use overflow: hidden  to contain floating objects (floats). A better alternative is to use  micro clearfix .
  3. The key  ! important  should not be used where a specification is sufficient.
  4. Putting on Google expects a source of several blocks of characters includes conditionally blocks with gettext.
  5. Are not permitted in the style attributes HTML tags.
Conflict with plugins

The environment WordPress.com is overloaded with a lot of plugins that provide functionality shared by all threads. To give users a consistent experience should not be included in the topics that duplicate functionality of plugins. This should also be applicable to other settings.

When designing themes for WordPress.com this is what is used:
  1. Advertising options are managed  WordAds .
  2. Custom color settings are managed with the plugin  Custom Colors .
  3. Custom font settings are managed with the plugin  Custom Fonts .
  4. The favicons are managed with the plugin  Blavatar .
  5. Support is used  HiDPI  for pictures uploaded by users
  6. The infinite scroll it offers  Jetpack .
  7. Open Graph Protocol
  8. Support Twitter meta tag
  9. Different  widgets
Data Portability

Ensure that user content does not change when the subject is very important. The following features of the standard installation of WordPress, but are great by themselves, can cause a change in the content of the user or may not be available if activated from the topic.
  1. Entry Types personalize public
  2. Public custom taxonomies
  3. Custom Fields field goal or tickets
  4. Shortcodes (shortcodes)
Theme Options

If your theme includes custom settings is highly recommended to use the customizer instead of a custom screen management. Doing so has many advantages:
  1. Users can see your changes immediately, as it adapts to the user interface.
  2. You have to write a lot less code.
  3. You have user interface modules for most common situations.
If your item needs to offer a management screen custom settings these are the requirements:
  1. Must be a child menu Appearance menu, with the title "Theme Options".
  2. It requires the use of the  Settings API  in WordPress.
  3. All adjustments should save an "array" series.
  4. The default settings should not be inserted in the database until the installation or an http request.
  5. All values ​​must be sanitized before storing them in the database.
  6. You must use the functionality of the standard installation for any need for file uploads.
Most of these requirements, if not all, are in the  sample settings file topics for beginners .

  1. They used the "loops" complete in all templates. It is not enough simply to call the_post () in single.php or page.php template how.
  2. The  $ content_width  overall should be well defined.
complete in all templates
Usability Guides

The  unit test data for WordPress.org themes  is full of entries and pages designed to carry your theme to its limits. Download  the data  and import them to your test server. Test your theme with all available tests will help you ensure that your topic will be flexible enough to handle a wide variety of real user data.

Translation (something free but required in vital) of Theme guide


  1. Great article with a great content. As a Wordpress user I have seen so many Wordpress users just using Wordpress without knowing the what Wordpress can do. This would be a great help for them.

  2. Actually I’m like to create several kinds of blogs. I used blog spot and word press.
    There have a to z information about create blog with word press.