Home » wordpress主题 » WordPress Theme Standards En

WordPress Theme Standards En

# style.css

Theme name must not use keyword like WordPress, Theme.
Text domain must be mentioned. Example: Text Domain: my-nepal
Theme URI and Author URI are optional. If used Theme URI link with the page of theme information and Author URI link with the author personal site or project development site. Avoid using ‘wordpress.org’ as Theme or Author URI.

License and License URI must be included.
Version of theme should be mentioned.
Theme Tags should be written.
Only three subject tags are allowed.(Example: Blog, Portfolio, Corporate)

# License

Always pay extra attention and make sure that the entire theme is GPL, or GPL-Compatible. This will include, fonts, scripts, images etc.
Check all given links for GPL license and sure all mentioned URL’s are GPL compatible.
External components without GPL license are not allowed.

# Security and Privacy

Don’t phone home without informed user consent.
Make any collection of user data “opt-in” only and have a theme option that is set to disabled by default.

# Sanitization and Validation

Sanitize every theme options used in the theme. You should always escape theme options while output.
Escaping URL for ensuring no additional texts & characters are there. Example: ”>Home
Escaping HTML for ensuring no additional texts & characters are there. Example: $html = esc_html( ‘A link’ );
Escaping text area & attribute for ensuring no additional texts & characters are there. Example:
Escaping URL for image source. Example:
Reference Link: http://code.tutsplus.com/articles/data-sanitization-and-validation-with-wordpress–wp-25536

#Content Creation

Content Creation like Text area are not allowed on Customizer or Widgets.

# Theme Options

Settings API is not allowed on theme for Theme Options. Use Customizer API to implement theme options.
Only one subpage is allowed under Appearance menu. And that should contain relevant information about theme like documentation, user guide, etc.

# Language

Can use any language for text, but only use the same one for all text.
Themes are required to use as string as the text domain in translation functions.
Theme must be translation ready. All string need to be translate able. Example: ‘Category:’ it’s translation ready is
Text domain must be mentioned on ‘style.css’. It must match with the theme name. If theme name is “My Nepal” its text domain is ‘my-nepal’.
‘.pot’ must be inside the languages folder and name must be ‘textdomain.pot’.
Languages must be load on theme file by ‘load_theme_textdomain(‘textdomain’, get_template_directory() . ‘/languages’);’

# Readme

Make sure ‘readme.txt’ in is theme root directory.
If other file like ‘readme.md’,’theme-info.txt’ found on theme directory, recommended to use ‘readme.txt’ request to remove other files.
‘readme.txt’ must contain theme info, license info, changelog , short theme description etc. Reference: https://make.wordpress.org/themes/2015/04/29/a-revised-readme/

# Screenshot

No logo or mock up, should be of actual theme it appears.
Size no bigger than 1200*900px. Any 4:3 image size is accepted.

# Changelog.txt

If changelog is not maintained on ‘readme.txt’ it must maintained under the ‘changelog.txt’.

# Favicon

This is now core functionality, new theme should not add this feature.

# Site Logo

If logo feature is implemented, Logo must be changeable and be disabled by default.

# Plugins

No plugins are not allowed to bundle in the theme, but theme can recommend plugins and those plugins must be in dot org repository. Theme should work good without any plugin.

# Post Type

Custom Post types and taxonomies are not allowed.

# Shortcode

No shortcodes are allowed on theme.

# Style and Scripts

Theme must have ‘style.css’.
No hard coding of style and scripts are allowed. Style and Scripts need to be enqueued.
Use ‘get_template_directory_uri()’ instead of ‘get_stylesheet_directory_uri()’.
No minification of style or scripts files are allowed unless original files are provided.
If Google font is used, it should be enqueued. No other CDN urls are allowed.
Default Scripts Included and Registered by WordPress itself. No need to enqueue, like ‘jquery.js, masonry.js’ etc
Use dependencies on scripts to reduce conflicts.

# header.php

Proper DOCTYPE is needed.
The opening ‘’ tag should include ‘language_attribute’.
Use ‘bloginfo()’ to set the ‘’ charset and description element.
Add a call to ‘wp_head()’ before the closing ‘’ tag. Plugins use this action hook to add their own scripts, stylesheets, and other functionality.
‘body_class()’must be inside the opening body tag.
Example: >

Do not link the theme stylesheets in the Header template. Use the ‘wp_enqueue_scripts’ action hook in a theme function instead.

# footer.php

Use the ‘wp_footer()’ call, to appear just before closing body tag.

# Customizer API

‘capability’ should be ‘edit_theme_options’ while using Customizer API for theme options.
‘sanitize_callback’ is necessary for sanitizing customizer fields. For example: Sanitizing URL ‘sanitize_callback’ => ‘esc_url_raw’
Sanitizing Email ‘sanitize_callback’ => ‘sanitize_email’ etc.

# Code

add_theme_support( ‘title-tag’ ); must be included on functions.php. Title tag is not allowed in ‘header.php’. If <?php wp_title(‘|’); ?> found, it is not allowed because title tag already defined.
Prefix theme functions, classes, global variables, image size name, script and style handles, etc with the theme slug.
Example:

function textdomain_footer_copyright{

//code goes here

}

No any PHP error & warning, Javascript’s console error, WordPress deprecated errors are allowed. Need to fix them.
Functions like ‘the_archive_title’ and ‘the_archive_description’ are now available in WordPress core. And thus, we don’t have to keep the backward compatibility for more than last two major versions. They must not be defined. Mostly they are defined in ‘template-tags.php’.

# Others

W and P of WordPress always in uppercase.
Remove out unnecessary commented code. If any file or folder is not being used, it should be removed.
It is not necessary to provide backward compatibility more the two major versions.
No customization in WordPress admin.
Redirection is not allowed after theme activated.
Custom CSS field is not allowed. It’s now core functionality. (Since WordPress 4.7)
It’s not allowed to remove the default functionality of core.

雨田

一个喜欢折腾wordpress的爱好者,希望与大家一起探讨wp技术!