Theme Development WordPress Codex
Theme Development WordPress Codex
Theme Development «
WordPress Codex
Languages:বাংলা • English • Español • 日本語한국어 • Português do Brasil • Русский
• 中文 简体 中文 繁體
( )• ( ) • (Add your language)
This article is about developing WordPress Themes. If you wish to learn more about
how to install and use Themes, review Using Themes. This topic differs from Using
Themes because it discusses the technical aspects of writing code to build your
own Themes rather than how to activate Themes or where to obtain new Themes.
https://codex.wordpress.org/Theme_Development 1/10
06/08/23, 00:37 Theme Development « WordPress Codex
It removes the need for a typical WordPress site owner to have to learn CSS, HTML,
and PHP in order to have a great-looking website.
Why should you build your own WordPress Theme? That's the real question.
It's an opportunity to learn more about CSS, HTML, and PHP.
It's an opportunity to put your expertise with CSS, HTML, and PHP to work.
It's creative.
It's fun (most of the time).
If you release it to the public, you can feel good that you shared and gave
something back to the WordPress Community (okay, bragging rights)
Anatomy of a Theme
WordPress Themes live in subdirectories of the WordPress themes directory (wp-
content/themes/ by default) which cannot be directly moved using the wp-
config.php file. The Theme's subdirectory holds all of the Theme's stylesheet files,
template files, and optional functions file (functions.php), JavaScript files, and
images. For example, a Theme named "test" would reside in the directory wp-
content/themes/test/. Avoid using numbers for the theme name, as this prevents it
from being displayed in the available themes list.
WordPress includes a default theme in each new installation. Examine the files in
the default theme carefully to get a better idea of how to build your own Theme
files.
For a visual guide, see this infographic on WordPress Theme Anatomy.
WordPress Themes typically consist of three main types of files, in addition to
images and JavaScript files.
1. The stylesheet called style.css, which controls the presentation (visual design and
layout) of the website pages.
2. WordPress template files which control the way the site pages generate the
information from your WordPress database to be displayed on the site.
3. The optional functions file (functions.php) as part of the WordPress Theme files.
https://codex.wordpress.org/Theme_Development 2/10
06/08/23, 00:37 Theme Development « WordPress Codex
Child Themes
This section has moved to the Theme Developer Handbook:
https://developer.wordpress.org/themes/advanced-topics/child-themes/
Theme Stylesheet
This section has moved to the Theme Developer Handbook:
https://developer.wordpress.org/themes/basics/main-stylesheet-style-css/
Functions File
This section has moved to the Theme Developer Handbook:
https://developer.wordpress.org/themes/basics/theme-functions/
Template Files
This section has moved to the Theme Developer Handbook:
https://developer.wordpress.org/themes/basics/template-files/
https://codex.wordpress.org/Theme_Development 3/10
06/08/23, 00:37 Theme Development « WordPress Codex
Untrusted Data
This section has moved to the Security page in the Common APIs Handbook:
https://developer.wordpress.org/apis/security/
Theme Classes
https://codex.wordpress.org/Theme_Development 4/10
06/08/23, 00:37 Theme Development « WordPress Codex
The Theme should be widgetized as fully as possible. Any area in the layout that
works like a widget (tag cloud, blogroll, list of categories) or could accept widgets
(sidebar) should allow widgets.
Content that appears in widgetized areas by default (hard-coded into the sidebar,
for example) should disappear when widgets are enabled from Appearance >
Widgets.
Use the wp_footer() call, to appear just before closing body tag.
<?php wp_footer(); ?>
</body>
</html>
Index (index.php)
Display a list of posts in excerpt or full-length form. Choose one or the other as
appropriate.
Include wp_link_pages() to support navigation links within posts.
Archive (archive.php)
Display archive title (tag, category, date-based, or author archives).
Display a list of posts in excerpt or full-length form. Choose one or the other as
appropriate.
Include wp_link_pages() to support navigation links within posts.
Pages (page.php)
Display page title and page content.
Display comment list and comment form (unless comments are off).
Include wp_link_pages() to support navigation links within a page.
Metadata such as tags, categories, date and author should not be displayed.
Display an "Edit" link for logged-in users with edit permissions.
https://codex.wordpress.org/Theme_Development 6/10
06/08/23, 00:37 Theme Development « WordPress Codex
It's a good practice to include the search form again on the results page. Include it
with: get_search_form().
JavaScript
This section has moved to the Theme Developer Handbook:
https://developer.wordpress.org/themes/basics/including-css-javascript/
https://codex.wordpress.org/Theme_Development 7/10
06/08/23, 00:37 Theme Development « WordPress Codex
Screenshot
Create a screenshot for your theme. The screenshot should be named
screenshot.png, and should be placed in the top level directory. The screenshot
should accurately show the theme design and saved in PNG format. While .jpg,
.jpeg, and .gif are also valid extensions and file formats for the screenshot, they are
not recommended.
The recommended image size is 1200px wide by 900px tall. The screenshot will
usually be shown smaller but the over-sized image allows for high-resolution
viewing on HiDPI displays. Note that because the Manage Themes screen is
responsive, the top and bottom of the screenshot image might not be viewable so
keep graphics near the center.
Theme Options
Themes can optionally support the Theme Customize Screen. For an example code,
see A Sample WordPress Theme Options Page.
When enabling the availability of the Theme Customize Screen for a user role, use
the "edit_theme_options" user capability instead of the "switch_themes" capability
unless the user role actually should also be able to switch the themes. See more at
Roles and Capabilities and Adding Administration Menus.
If you are using the "edit_themes" capability anywhere in your Theme to gain the
Administrator role access to the Theme Customize Screen (or maybe some custom
screens), be aware that since Version 3.0, this capability has not been assigned to
the Administrator role by default in the case of WordPress Multisite installation.
See the explanation. In such a case, use the "edit_theme_options" capability
instead if you want the Administrator to see the "Theme Options" menu. See the
additional capabilities of Administrator role when using WordPress Multisite.
https://codex.wordpress.org/Theme_Development 8/10
06/08/23, 00:37 Theme Development « WordPress Codex
Code Standards
Know Your Sources
WordPress Coding Standards
CSS Coding Standards
Theme Design
Site Design and Layout
CSS
CSS
CSS Shorthand
WordPress Generated Classes
Templates
Stepping Into Templates
Templates
Template Hierarchy
Template Tags
The Loop
Conditional Tags
Function Reference
I18n for WordPress Developers
Data Validation
Functions listing
Function Reference
Testing and QA
Theme Unit Test
Validating a Website
CSS Fixing Browser Bugs
CSS Troubleshooting
https://codex.wordpress.org/Theme_Development 9/10
06/08/23, 00:37 Theme Development « WordPress Codex
https://codex.wordpress.org/Theme_Development 10/10