# Credits Source: https://developer.wordpress.org/themes/credits/ - @ancawonka - @Anthonynotes - @atachibana - @austingunter - @bandonrandon - @utz119 - @BFTrick - @BigActual - @bkozma - @boborchard - @Brainfestation - @celloexpressions - @charliehanger - @claymonk - @code\_poet - @colorful-tones - @crondeau - @davidjlaietta - @daisyo - @digisavvy - @DrewAPicture - @enricchi - @esmi - @fabianapsimoes - @fiveo - @grapplerulrich - @greenshady - @hanni - @hlashbrooke - @hardeepasrani - @iandstewart - @jackreichert - @jacobmc - @JasonM4563 - @jazzs3quence - @jboydston - @jcastaneda - @jcrglobalcaplaw - @JenniferBourn - @jerrysarcastic - @jgclarke - @jhoffm34 - @jim-spencer - @jimdoran - @juhise - @juliekuehl - @kadamwhite - @kafleg - @karmatosed - @kenshino - @kenyasullivan - @kpdesign - @lettergrade - @linux-garage - @lizkaraffa - @lorax - @mariawoothemescom - @markel - @martydia - @missybunnie - @mt\_Suzette - @nao - @NikV - @Otto42 - @ozzyr - @philiparthurmoore - @poena - @PriscillaBiju - @rachelbaker - @Raporteur - @rahulsprajapati - @rclations - @rhauptman - @RussE - @ryanr14 - @SagarGurnani - @samuelsidler - @sarahovenall - @semblance\_er - @sewmyheadon - @SeReedMedia - @sheebaabraham - @siobhan - @stubbs123 - @suastex - @sushil-adhikari - @Techdoode - @thepixelista - @topher1kenobe - @TJNowell - @xfrontend - @viniciuslourenco - @vrm --- # Page Templates Source: https://developer.wordpress.org/themes/template-files-section/page-template-files/ Page templates are a specific type of [template file](https://developer.wordpress.org/themes/basics/template-files/ "Template Files") that can be applied to a specific page or groups of pages. As of WordPress 4.7 page templates support all post types. For more details how to set a page template to specific post types [see example below](#creating-page-templates-for-specific-post-types). Since a page template is a specific type of template file, here are some distinguishing features of page templates: - Page templates are used to change the look and feel of a page. - A page template can be applied to a single page, a page section, or a class of pages. - Page templates generally have a high level of specificity, targeting an individual page or group of pages. For example, a page template named `page-about.php` is more specific than the template files `page.php` or `index.php` as it will only affect a page with the slug of “about.” - If a page template has a template name, WordPress users editing the page have control over what template will be used to render the page. ## Uses for Page Templates Page templates display your site’s dynamic content on a page, e.g., posts, news updates, calendar events, media files, etc. You may decide that you want your homepage to look a specific way, that is quite different to other parts of your site. Or, you may want to display a featured image that links to a post on one part of the page, have a list of latest posts elsewhere, and use a custom navigation. You can use page templates to achieve these things. This section shows you how to build page templates that can be selected by your users through their admin screens. For example, you can build page templates for: - full-width, one-column - two-column with a sidebar on the right - two-column with a sidebar on the left - three-column ## Page Templates within the Template Hierarchy When a person browses to your website, WordPress selects which template to use for rendering that page. As we learned earlier in the [Template Hierarchy](https://developer.wordpress.org/themes/basics/template-hierarchy/ "Template Hierarchy"), WordPress looks for template files in the following order: 1. **Page Template —** If the page has a custom template assigned, WordPress looks for that file and, if found, uses it. 2. **`page-{slug}.php` —** If no custom template has been assigned, WordPress looks for and uses a specialized template that contains the page’s slug. 3. **`page-{id}.php` —** If a specialized template that includes the page’s slug is not found, WordPress looks for and uses a specialized template named with the page’s ID. 4. **`page.php` —** If a specialized template that includes the page’s ID is not found, WordPress looks for and uses the theme’s default page template. 5. **`singular.php` —** If `page.php` is not found, WordPress looks for and uses the theme’s template used for a single post, irregardless of post type. 6. **`index.php` —** If no specific page templates are assigned or found, WordPress defaults back to using the theme’s index file to render pages. There is also a WordPress-defined template named `paged.php`. It is *not* used for the page post-type but rather for displaying multiple pages of archives. ## Page Templates Purpose & User Control If you plan on making a custom page template for your theme, you should decide a couple of things before proceeding: - Whether the page template will be for one specific page or for any page; and - What type of user control you want available for the template. Every page template that has a template name can be selected by a user when they create or edit a page. The list of available templates can be found at **Pages > Add New > Attributes > Template**. Therefore, a WordPress user can choose any page template with a template name, which might not be your intention. For example, if you want to have a specific template for your “About” page, it might not be appropriate to name that page template “About Template” as it would be globally available to all pages (i.e. the user could apply it to any page). Instead, [create a single use template](https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-a-custom-page-template-for-one-specific-page) and WordPress will render the page with the appropriate template, whenever a user visits the “About” page. Conversely, many themes include the ability to choose how many columns a page will have. Each of these options is a page template that is available globally. To give your WordPress users this global option, you will need to create page templates for each option and give each a template name. Dictating whether a template is for global use vs. singular use is achieved by the way the file is named and whether or not is has a specific comment. Sometimes it is appropriate to have a template globally available even if it appears to be a single use case. When you’re creating themes for release, it can be hard to predict what a user will name their pages. Portfolio pages are a great example as not every WordPress user will name their portfolio the same thing or have the same page ID and yet they may want to use that template. ## File Organization of Page Templates As discussed in [Organizing Theme Files](https://developer.wordpress.org/themes/basics/organizing-theme-files/), WordPress recognizes the subfolder **page-templates**. Therefore, it’s a good idea to store your global page templates in this folder to help keep them organized. A specialized page template file (those created for only one time use) **cannot** be in a sub-folder, nor, if using a [Child Theme](https://developer.wordpress.org/themes/advanced-topics/child-themes/#how-to-create-a-child-theme), in the Parent Theme’s folder. ## Creating Custom Page Templates for Global Use Sometimes you’ll want a template that can be used globally by any page, or by multiple pages. Some developers will group their templates with a filename prefix, such as `page_two-columns.php` ***Important!*** Do not use `page-` as a prefix, as WordPress will interpret the file as a specialized template, meant to apply to only *one* page on your site. For information on theme file-naming conventions and filenames you cannot use, see [reserved theme filenames](https://developer.wordpress.org/themes/basics/template-files/#common-wordpress-template-files "Theme Development"). A quick, safe method for creating a new page template is to make a copy of `page.php` and give the new file a distinct filename. That way, you start off with the HTML structure of your other pages and you can edit the new file as needed. To create a global template, write an opening PHP comment at the top of the file that states the template’s name. ```php ``` It’s a good idea to choose a name that describes what the template does as the name is visible to WordPress users when they are editing the page. For example, you could name your template Homepage, Blog, or Portfolio. This example from the TwentyFourteen theme creates a page template called Full Width Page: ```php body_class()` function, WordPress will print classes in the `body` tag for the post type class name (`page`), the page’s ID (`page-id-{ID}`), and the page template used. For the default `page.php`, the class name generated is `page-template-default`: ```markup
``` A specialized template (`page-{slug}.php` or `page-{ID}.php`) also gets the `page-template-default` class rather than its own body class. When using a custom page template, the class `page-template` will print, along with a class naming the specific template. For example, if your custom page template file is named as follows: ```php ``` Then then rendered HTML generated will be as follows: ```markup ``` Notice the `page-template-my-custom-page-php` class that is applied to the `body` tag. ## Page Template Functions These built-in WordPress functions and methods can help you work with page templates: - `get_page_template()` returns the path of the page template used to render the page. - `wp_get_theme()->get_page_templates()` returns all custom page templates available to the currently active theme (`get_page_templates()` is a method of the `WP_Theme` class). - `is_page_template()` returns true or false depending on whether a custom page template was used to render the page. - `get_page_template_slug()` returns the value of custom field `_wp_page_template` (`null` when the value is empty or “default”).If a page has been assigned a custom template, the filename of that template is stored as the value of a [custom field](https://codex.wordpress.org/Custom_Fields "Custom Fields") named `'_wp_page_template'` (in the [`wp_postmeta`](https://codex.wordpress.org/Database_Description#Table:_wp_postmeta "Database Description") database table). (Custom fields starting with an underscore do not display in the edit screen’s custom fields module.) --- # Template Hierarchy Source: https://developer.wordpress.org/themes/basics/template-hierarchy/ As discussed, [template files](https://developer.wordpress.org/themes/basics/template-files/ "Template files page") are modular, reusable files, used to generate the web pages on your WordPress site. Some template files (such as the header and footer template) are used on all of your site’s pages, while others are used only under specific conditions. This article explains **how WordPress determines which template file(s) to use on individual pages**. If you want to customize an existing WordPress theme it will help you decide which template file needs to be edited. You can also use [Conditional Tags](https://developer.wordpress.org/themes/basics/conditional-tags/ "Conditional Tags") to control which templates are loaded on a specific page. ## The Template File Hierarchy ### Overview WordPress uses the [query string](https://wordpress.org/support/article/glossary/#query-string) to decide which template or set of templates should be used to display the page. The query string is information that is contained in the link to each part of your website. Put simply, WordPress searches down through the template hierarchy until it finds a matching template file. To determine which template file to use, WordPress: 1. Matches every query string to a query type to decide which page is being requested (for example, a search page, a category page, etc); 2. Selects the template in the order determined by the template hierarchy; 3. Looks for template files with specific names in the current theme’s directory and uses the **first matching template file** as specified by the hierarchy. With the exception of the basic `index.php` template file, you can choose whether you want to implement a particular template file or not. In these examples, the PHP file extension is used. In block themes, HTML files are used instead, but the template hierarchy is the same. If WordPress cannot find a template file with a matching name, it will skip to the next file in the hierarchy. If WordPress cannot find any matching template file, the theme’s `index.php` file will be used. When you are using a [child theme](https://developer.wordpress.org/themes/advanced-topics/child-themes/), any file you add to your child theme will over-ride the same file in the parent theme. For example, both themes contain the same template `category.php`, then child theme’s template is used. If a child theme contains the specific template such as `category-unicorns.php` and the parent theme contains lower prioritized template such as `category.php`, then child theme’s `category-unicorns.php` is used. Contrary, if a child theme contains general template only such as `category.php` and the parent theme contains the specific one such as `category-unicorns.php`, then parent’s template `category-unicorns.php` is used. ### Examples If your blog is at `http://example.com/blog/` and a visitor clicks on a link to a category page such as `http://example.com/blog/category/your-cat/`, WordPress looks for a template file in the current theme’s directory that matches the category’s ID to generate the correct page. More specifically, WordPress follows this procedure: 1. Looks for a template file in the current theme’s directory that matches the category’s slug. If the category slug is “unicorns,” then WordPress looks for a template file named `category-unicorns.php`. 2. If `category-unicorns.php` is missing and the category’s ID is 4, WordPress looks for a template file named `category-4.php`. 3. If `category-4.php` is missing, WordPress will look for a generic category template file, `category.php`. 4. If `category.php` does not exist, WordPress will look for a generic archive template, `archive.php`. 5. If `archive.php` is also missing, WordPress will fall back to the main theme template file, `index.php`. ### Visual Overview The following diagram shows which template files are called to generate a WordPress page based on the WordPress template hierarchy. [](https://i0.wp.com/developer.wordpress.org/files/2014/10/Screenshot-2019-01-23-00.20.04.png?ssl=1)## The Template Hierarchy In Detail While the template hierarchy is easier to understand as a diagram, the following sections describe the order in which template files are called by WordPress for a number of query types. ### Home Page display By default, WordPress sets your site’s home page to display your latest blog posts. This page is called the blog posts index. You can also set your blog posts to display on a separate static page. The template file `home.php` is used to render the blog posts index, whether it is being used as the front page or on separate static page. If `home.php` does not exist, WordPress will use `index.php`. 1. `home.php` 2. `index.php` If `front-page.php` exists, it will override the `home.php` template. ### Front Page display The `front-page.php` template file is used to render your site’s front page, whether the front page displays the blog posts index (mentioned above) or a static page. The front page template takes precedence over the blog posts index (`home.php`) template. If the `front-page.php` file does not exist, WordPress will either use the `home.php` or `page.php` files depending on the setup in Settings → Reading. If neither of those files exist, it will use the `index.php` file. 1. `front-page.php` – Used for both “**your latest posts**” or “**a static page**” as set in the **front page displays** section of Settings → Reading. 2. `home.php` – If WordPress cannot find `front-page.php` and “**your latest posts**” is set in the **front page displays** section, it will look for `home.php`. Additionally, WordPress will look for this file when the **posts page** is set in the **front page displays** section. 3. `page.php` – When “**front page**” is set in the **front page displays** section. 4. `index.php` – When “**your latest posts**” is set in the **front page displays** section but `home.php` does not exist *or* when **front page** is set but `page.php` does not exist. As you can see, there are a lot of rules to what path WordPress takes. Using the chart above is the best way to determine what WordPress will display. ### Privacy Policy Page display The `privacy-policy.php` template file is used to render your site’s Privacy Policy page. The Privacy Policy page template takes precedence over the static page (`page.php`) template. If the `privacy-policy.php` file does not exist, WordPress will either use the `page.php` or `singular.php` files depending on the available templates. If neither of those files exist, it will use the `index.php` file. 1. `privacy-policy.php` – Used for the Privacy Policy page set in the **Change your Privacy Policy page** section of Settings → Privacy. 2. `custom template file` – The [page template](https://developer.wordpress.org/themes/template-files-section/page-template-files/) assigned to the page. See `get_page_templates()`. 3. `page-{slug}.php` – If the page slug is `privacy`, WordPress will look to use `page-privacy.php`. 4. `page-{id}.php` – If the page ID is 6, WordPress will look to use `page-6.php`. 5. `page.php` 6. `singular.php` 7. `index.php` ### Single Post The single post template file is used to render a single post. WordPress uses the following path: 1. `single-{post-type}-{slug}.php` – (Since 4.4) First, WordPress looks for a template for the specific post. For example, if [post type](https://developer.wordpress.org/themes/basics/post-types/) is `product` and the post slug is `dmc-12`, WordPress would look for `single-product-dmc-12.php`. 2. `single-{post-type}.php` – If the post type is `product`, WordPress would look for `single-product.php`. 3. `single.php` – WordPress then falls back to `single.php`. 4. `singular.php` – Then it falls back to `singular.php`. 5. `index.php` – Finally, as mentioned above, WordPress ultimately falls back to `index.php`. ### Single Page The template file used to render a static page (`page` post-type). Note that unlike other post-types, `page` is special to WordPress and uses the following path: 1. `custom template file` – The [page template](https://developer.wordpress.org/themes/template-files-section/page-template-files/) assigned to the page. See `get_page_templates()`. 2. `page-{slug}.php` – If the page slug is `recent-news`, WordPress will look to use `page-recent-news.php`. 3. `page-{id}.php` – If the page ID is 6, WordPress will look to use `page-6.php`. 4. `page.php` 5. `singular.php` 6. `index.php` ### Category Rendering category archive index pages uses the following path in WordPress: 1. `category-{slug}.php` – If the category’s slug is `news`, WordPress will look for `category-news.php`. 2. `category-{id}.php` – If the category’s ID is `6`, WordPress will look for `category-6.php`. 3. `category.php` 4. `archive.php` 5. `index.php` ### Tag To display a tag archive index page, WordPress uses the following path: 1. `tag-{slug}.php` – If the tag’s slug is `sometag`, WordPress will look for `tag-sometag.php`. 2. `tag-{id}.php` – If the tag’s ID is `6`, WordPress will look for `tag-6.php`. 3. `tag.php` 4. `archive.php` 5. `index.php` ### Custom Taxonomies [Custom taxonomies](https://developer.wordpress.org/themes/basics/categories-tags-custom-taxonomies/) use a slightly different template file path: 1. `taxonomy-{taxonomy}-{term}.php` – If the taxonomy is `sometax`, and taxonomy’s term is `someterm`, WordPress will look for `taxonomy-sometax-someterm.php.` In the case of [post formats](https://developer.wordpress.org/themes/functionality/post-formats/), the taxonomy is ‘post\_format’ and the terms are ‘post-format-{format}. i.e. `taxonomy-post_format-post-format-link.php` for the link post format. 2. `taxonomy-{taxonomy}.php` – If the taxonomy were `sometax`, WordPress would look for `taxonomy-sometax.php`. 3. `taxonomy.php` 4. `archive.php` 5. `index.php` ### Custom Post Types [Custom Post Types](https://developer.wordpress.org/themes/basics/post-types/) use the following path to render the appropriate archive index page. 1. `archive-{post_type}.php` – If the post type is `product`, WordPress will look for `archive-product.php`. 2. `archive.php` 3. `index.php` (For rendering a single post type template, refer to the [single post display](#single-post "Single Post Display") section above.) ### Author display Based on the above examples, rendering author archive index pages is fairly explanatory: 1. `author-{nicename}.php` – If the author’s nice name is `matt`, WordPress will look for `author-matt.php`. 2. `author-{id}.php` – If the author’s ID were `6`, WordPress will look for `author-6.php`. 3. `author.php` 4. `archive.php` 5. `index.php` ### Date Date-based archive index pages are rendered as you would expect: 1. `date.php` 2. `archive.php` 3. `index.php` ### Search Result Search results follow the same pattern as other template types: 1. `search.php` 2. `index.php` ### 404 (Not Found) Likewise, 404 template files are called in this order: 1. `404.php` 2. `index.php` ### Attachment Rendering an attachment page (`attachment` post-type) uses the following path: 1. `{MIME-type}.php` – can be any [MIME type](http://en.wikipedia.org/wiki/Internet_media_type "http://en.wikipedia.org/wiki/Internet_media_type") (For example: `image.php`, `video.php`, `pdf.php`). For `text/plain`, the following path is used (in order): 1. `text-plain.php` 2. `plain.php` 3. `text.php` 2. `attachment.php` 3. `single-attachment-{slug}.php` – For example, if the attachment slug is `holiday`, WordPress would look for `single-attachment-holiday.php`. 4. `single-attachment.php` 5. `single.php` 6. `singular.php` 7. `index.php` As of WordPress 6.4, attachment pages are [no longer enabled by default](https://make.wordpress.org/core/2023/10/16/changes-to-attachment-pages/) on new installations. Users can enable them with a plugin, so it is still good practice to test your theme and ensure it properly displays content when viewing an attachment page. ### Embeds The embed template file is used to render a post which is being embedded. Since 4.5, WordPress uses the following path: 1. `embed-{post-type}-{post_format}.php` – First, WordPress looks for a template for the specific post. For example, if its post type is `post` and it has the audio format, WordPress would look for `embed-post-audio.php`. 2. `embed-{post-type}.php` – If the post type is `product`, WordPress would look for `embed-product.php`. 3. `embed.php` – WordPress then falls back to embed`.php`. 4. Finally, WordPress ultimately falls back to its own `wp-includes/theme-compat/embed.php` template. ## Non-ASCII Character Handling Since WordPress 4.7, any dynamic part of a template name which includes non-ASCII characters in its name actually supports both the un-encoded and the encoded form, in that order. You can choose which to use. Here’s the page template hierarchy for a page named “Hello World 😀” with an ID of `6`: - `page-hello-world-😀.php` - `page-hello-world-%f0%9f%98%80.php` - `page-6.php` - `page.php` - `singular.php` The same behaviour applies to post slugs, term names, and author nicenames. ## Filter Hierarchy The WordPress template system lets you filter the hierarchy. This means that you can insert and change things at specific points of the hierarchy. The filter (located in the [`get_query_template()`](https://developer.wordpress.org/reference/functions/get_query_template/) function) uses this filter name: `"{$type}_template"` where `$type` is the template type. Here is a list of all available filters in the template hierarchy: - `embed_template` - `404_template` - `search_template` - `frontpage_template` - `home_template` - `privacypolicy_template` - `taxonomy_template` - `attachment_template` - `single_template` - `page_template` - `singular_template` - `category_template` - `tag_template` - `author_template` - `date_template` - `archive_template` - `index_template` ### Example For example, let’s take the default author hierarchy: - `author-{nicename}.php` - `author-{id}.php` - `author.php` To add `author-{role}.php` before `author.php`, we can manipulate the actual hierarchy using the ‘author\_template’ template type. This allows a request for /author/username where username has the role of editor to display using author-editor.php if present in the current themes directory. ```php function author_role_template( $templates = '' ) { $author = get_queried_object(); $role = $author->roles[0]; if ( ! is_array( $templates ) && ! empty( $templates ) ) { $templates = locate_template( array( "author-$role.php", $templates ), false ); } elseif ( empty( $templates ) ) { $templates = locate_template( "author-$role.php", false ); } else { $new_template = locate_template( array( "author-$role.php" ) ); if ( ! empty( $new_template ) ) { array_unshift( $templates, $new_template ); } } return $templates; } add_filter( 'author_template', 'author_role_template' ); ``` Changelog: - **Updated** 2022-02-15. Added a notice explaining that the template hierarchy is the same for classic and block themes, but that the examples uses .php files and block themes use .html files. --- # Template Tags Source: https://developer.wordpress.org/themes/basics/template-tags/ Template tags are used within themes to **retrieve content from your database**. The content could be anything from a blog title to a complete sidebar. Template tags are the preferred method to pull content into your theme because: - they can print dynamic content; - they can be used in multiple theme files; and - they separate the theme into smaller, more understandable, sections. ## What is a Template Tag? A template tag is simply a piece of code that tells WordPress to get something from the database. It is broken up into three components: - A PHP code tag - A WordPress function - Optional parameters You can use a template tag to call another theme file or some information from the database. For example, the template tag `get_header()` tells WordPress to get the `header.php` file and include it in the current theme file. Similarly, `get_footer()` tells WordPress to get the footer.php file. There are also other kinds of template tags: - `the_title()` – tells WordPress to get the title of the page or post from the database and include it. - `bloginfo( 'name' )` – tells WordPress to get the blog title out of the database and include it in the template file. If you look closely at the last example, you will also see that there is a parameter between the parenthesis. Parameters let you do two things: 1. ask for specific pieces of information and 2. format the information in a certain way. [Parameters are covered extensively below](#parameters), but it’s useful to be aware that you can send WordPress-specific instructions for how you want the data presented. ## Why Use Template Tags By encapsulating all of the code for a particular chunk of content, template tags make it very easy to include various pieces of a template in a theme file and also to maintain the theme. It is far easier to create one `header.php` file and have all of your theme templates like `single.php`, `page.php`, `front-page.php`, etc. reference that one theme file using `get_header()` than copying and pasting the code into each theme file. It also makes maintenance easier. Whenever you make a change in your `header.php` file, the change is automatically carried over into all of your other theme files. Another reason to use template tags is to display dynamic data, i.e. data from the database. In your header, you could manually include the `title` tag, like so: ```xml
construct`: Set up your widget with a description, name, and display width in your admin. 2. `widget`: Process the widget options and display the HTML on your page. The `$args` parameter provides the HTML you can use to display the widget title class and widget content class. 3. `form`: Display the form that will be used to set the options for your widget. If your widget doesn’t have any options, you can skip this function (although it is still best practice to include it even if it’s empty). 4. `update`: Save the widget options to the database. If your widget doesn’t have any options, you can skip this function (although it is still best practice to include it even if it’s empty). ### Registering a Widget The [register\_widget()](https://developer.wordpress.org/reference/functions/register_widget/) function is used to register a widget. Call this function using the widgets\_init hook: ```php widgets_init` action to register your widget. Next you will declare the arguments you will use when creating your widget. There are four arguments you must define, `before_title`, `after_title`, `before_widget`, and `after_widget`. These arguments will define the code that wraps your widgets title and the widget itself. After defining your arguments, you will define the widgets function. This function takes two parameters, the `$args` array from before, and the `$instance` of the widget, and is the function that will process options from the form and display the HTML for the widget on the front-end of your site. In the example above the widget function simply outputs the widget title, while passing it through the `widget_title` filter. It then out puts a simple widget wrapper and the content of the widget’s text field. As outlined in the example, you can access the options from the widget that are stored in the `$instance`. Next you will define the form function. This function takes one parameter, `$instance`, and outputs the form that the user uses to create the widget in the Widgets admin screen. In the example above, the function starts by defining the `$title` and `$text` variables and setting them to the previously entered values, if those values exist. Then it outputs a simple form with a text field for the title and a textarea for the text content. Lastly you will define the update function. This function takes two parameters, `$new_instance` and `$old_instance`, and is responsible for updating your widgets with new options when they are submitted. Here you simply define `$instance` as an empty array. You then set the title and text keys to the `$new_instance` values if they exist. You then return `$instance`. Finally, when all of the above is defined, you instantiate your new widget class and test your work. ### Sample Widget ```php __( 'A Foo Widget', 'text_domain' ) ) // Args ); } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { extract( $args ); $title = apply_filters( 'widget_title', $instance['title'] ); echo $before_widget; if ( ! empty( $title ) ) { echo $before_title . $title . $after_title; } echo __( 'Hello, World!', 'text_domain' ); echo $after_widget; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. */ public function form( $instance ) { if ( isset( $instance['title'] ) ) { $title = $instance['title']; } else { $title = __( 'New title', 'text_domain' ); } ?>
the_widget()` to display it programmatically. The function accepts widget class names. You pass the widget class name to the function like this: ```php
This is some text that will display at the top of the Category page.
``` This text will only display on an archive page displaying posts in that category. #### Different Text on Some Category Pages What if you want to display different text based on the category page that the visitor is using? You could add default text to the main *category.php* file, and create special *category-{slug}.php* files each with their own version of the text, but this would create lots of files in your theme. Instead, you can use [conditional tags](https://developer.wordpress.org/themes/basics/conditional-tags/ "Conditional Tags"). Again, this code would be added before the loop: ```phpThis is the text to describe category A.
This is the text to describe category B.
This is some generic text to describe all other category pages, I could be left blank.
``` This code does the following: 1. Checks to see if the visitor has requested Category A. If yes, it displays the first piece of text. 2. Checks for category B if the user didn’t request category A. If yes, it displays the second piece of text. 3. Displays the default text, if neither was requested. #### Display Text only on First Page of Archive If you have more posts than fits on one page of your archive, the category splits into multiple pages. Perhaps you want to display static text, if the user is on the first page of the results. To do this, use a PHP if statement that looks at the value of the $paged WordPress variable. Put the following above The Loop: ```phpText for first page of Category archive.
``` This code asks whether the page displayed is the first page of the archive. If it is, the text for the first page is displayed. Otherwise, the text for the subsequent pages is displayed. ### Modify How Posts are Displayed #### Excerpts vs. Full Posts You can choose whether to display full posts or just excerpts. By displaying excerpts, you shorten the length of your archive page. Open your file and find the loop. Look for: ```php the_content() ``` And replace it with: ```php the_excerpt() ``` And if your theme is displaying excerpts but you want to display the full content, replace `the_excerpt` with `the_content`. --- # Categories, Tags, & Custom Taxonomies Source: https://developer.wordpress.org/themes/basics/categories-tags-custom-taxonomies/ Categories, tags, and taxonomies are all related and can be easily confused. We’ll use the example of building a theme for a recipe website to help break down categories, tags, and taxonomies. In our recipe website, the **categories** would be Breakfast, Lunch, Dinner, Appetizers, Soups, Salads, Sides, and Desserts. All recipes will fit within those categories, but users might want to search for something specific like chocolate desserts or ginger chicken dinners. Chocolate, ginger, and chicken are all examples of **tags**. They are another level of specificity that provides meaning to the user. Lastly, there are taxonomies. In reality, categories and tags are examples of default taxonomies which simply are a way to organize content. Taxonomies are the method of classifying content and data in WordPress. When you use a taxonomy you’re grouping similar things together. The taxonomy refers to the sum of those groups. As with Post Types, there are a number of default taxonomies, and you can also create your own. Recipes are normally organized by category and tag, but there are some other helpful ways to break the recipes down to be more user friendly. For example, the recipe website might want an easy way to display recipes by cook time. A custom taxonomy of cook time with 0-30 min, 30-min to an hour, 1 to 2 hours, 2+ hours would be a great breakdown. Additionally, cook method such as grill, oven, stove, refrigerator, etc would be another example of a custom taxonomy that would be relevant for the site. There could also be a custom taxonomy for how spicy the recipe is and then a rating from 1-5 on spiciness. ## Default Taxonomies The default taxonomies in WordPress are: - categories: a hierarchical taxonomy that organizes content in the *post* Post Type - tags: a non-hierarchical taxonomy that organizes content in the *post* Post Type - post formats: a method for creating formats for your posts. You can learn more about these on the [Post Formats](https://developer.wordpress.org/themes/functionality/post-formats/ "Post Formats") page. ### Terms Terms are items within your taxonomy. So, for example, if you have the *Animal* taxonomy you would have the terms, dogs, cats, and sheep. Terms can be created via the WordPress admin, or you can use the [wp\_insert\_term()](https://developer.wordpress.org/reference/functions/wp_insert_term/ "wp_insert_term") function. ## Database Schema Taxonomies and terms are stored in the following database tables: - wp\_terms – stores all of the terms - wp\_term\_taxonomy – places the term in a taxonomy - wp\_term\_relationships – relates the taxonomy to an object (for example, *category* to *post)* [](https://i0.wp.com/developer.wordpress.org/files/2014/10/taxonomy-schema.png?ssl=1)## Templates WordPress offers several different hierarchies of templates for categories, tags, or custom taxonomies. More details on their structure and usage may be found on the [Taxonomy Templates](https://developer.wordpress.org/themes/functionality/taxonomy-templates/ "Taxonomy Templates") page. ## Custom Taxonomies It is possible to create new taxonomies in WordPress. You may, for example, want to create an *author* taxonomy on a book review website, or an *actor* taxonomy on a film site. As with custom post type **it is recommended that you put this functionality in a plugin**. This ensures that when the user changes their website’s design, their content is preserved in the plugin. You can read more about creating custom taxonomies in the [Plugin Developer Handbook.](https://developer.wordpress.org/plugins/taxonomy/working-with-custom-taxonomies/ "Working with Custom Taxonomies") --- # Pagination Source: https://developer.wordpress.org/themes/functionality/pagination/ Pagination allows your user to *page* back and forth through multiple pages of content. WordPress can use pagination when: - Viewing lists of posts when more posts exist than can fit on one page, or - Breaking up longer posts by manually by using the following tag: `` ## Using Pagination to Navigate Post Lists The most common use for pagination in WordPress sites is to break up long lists of posts into separate pages. Whether you’re viewing a category, archive, or default index page for a blog or site, WordPress only shows 10 posts per page by default. Users can change the number of posts that appear on each page on the Reading screen: **Admin > Settings > Reading**. ## Examples ### Loop with Pagination This simplified example shows where you can add pagination functions for the main loop. Add the functions just before or after the loop. ```php ``` ### Methods for displaying pagination links When using any of these pagination functions outside the template file with the loop that is being paginated, you must call the global variable $wp_query. ```php function your_themes_pagination() { global $wp_query; echo paginate_links(); } ``` WordPress has numerous functions for displaying links to other pages in your loop. Some of these functions are only used in very specific contexts. You would use a different function on a single post page then you would on a archive page. The following section covers archive template pagination functions. The section after that cover single post pagination. #### Simple Pagination **posts\_nav\_link** One of the simplest methods is [posts\_nav\_link()](https://developer.wordpress.org/reference/functions/posts_nav_link/). Simply place the function in your template after your loop. This generates both links to the next page of posts and previous page of posts where applicable. This function is ideal for themes that have simple pagination requirements. ```php posts_nav_link(); ``` **next\_posts\_link & prev\_posts\_link** When building a theme, use [next\_posts\_link()](https://developer.wordpress.org/reference/functions/next_posts_link/) and [prev\_posts\_link()](https://developer.wordpress.org/reference/functions/previous_posts_link/). to have control over where the previous and next posts page link appears. ```php next_posts_link(); previous_posts_link(); ``` If you need to pass the pagination links to a PHP variable, you can use [get\_next\_posts\_link()](https://developer.wordpress.org/reference/functions/get_next_posts_link/) and [get\_previous\_posts\_link()](https://developer.wordpress.org/reference/functions/get_previous_posts_link/). ```php $next_posts = get_next_posts_link(); $prev_posts = get_previous_posts_link(); ``` #### Numerical Pagination When you have many pages of content it is a better experience to display a list of page numbers so the user can click on any one of the page links rather then having to repeatedly click next or previous posts. WordPress provides several functions for automatically displaying a numerical pagination list. **For WordPress 4.1+** If you want more robust pagination options, you can use [the\_posts\_pagination()](https://developer.wordpress.org/reference/functions/the_posts_pagination/) for WordPress 4.1 and higher. This will output a set of page numbers with links to previous and next pages of posts. ```php the_posts_pagination(); ``` **For WordPress prior to 4.1** If you want your pagination to support older versions of WordPress, you must use [paginate\_links()](https://developer.wordpress.org/reference/functions/paginate_links/). ```php echo paginate_links(); ``` #### Pagination Between Single Posts All of the previous functions should be used on index and archive pages. When you are viewing a single blog post, you must use [prev\_post\_link](https://developer.wordpress.org/reference/functions/previous_post_link/) and [next\_post\_link](https://developer.wordpress.org/reference/functions/next_post_link/). Place the following functions below the loop on your single.php. ```php previous_post_link(); next_post_link(); ``` ### Pagination within a post WordPress gives you a tag that can be placed in post content to enable pagination for that post: `\` If you use that tag in the content, you need to ensure that the [wp\_link\_pages](https://developer.wordpress.org/reference/functions/wp_link_pages/) function is placed in your single.php template within the loop. ```php ``` --- # Comment Template Source: https://developer.wordpress.org/themes/template-files-section/partial-and-miscellaneous-template-files/comment-template/ WordPress displays comments in your theme based on the settings and code in the `comments.php` file within your WordPress theme. ## Simple comments loop ```php // Get only the approved comments $args = array( 'status' => 'approve', ); // The comment Query $comments_query = new WP_Comment_Query(); $comments = $comments_query->query( $args ); // Comment Loop if ( $comments ) { foreach ( $comments as $comment ) { echo '' . $comment->comment_content . '
'; } } else { echo 'No comments found.'; } ``` The `comments.php` template contains all the logic needed to pull comments out of the database and display them in your theme. Before we explore the template file you’ll want to know how to pull in the partial template file on the appropriate pages such as `single.php`. You’ll wrap the comment [template tag](https://developer.wordpress.org/themes/basics/template-tags/) in a conditional statement so comments.php is only pulled in if it makes sense to do. ```php // If comments are open or we have at least one comment, load up the comment template. if ( comments_open() || get_comments_number() ) : comments_template(); endif; ``` ## Another comments.php Example Here’s an example of the `comments.php` template included with the Twenty Thirteen theme: ```php
```
## Descriptive Anchor Text
The anchor text is the visible text for a hyperlink. Good link text should give the reader an idea of the action that will take place when clicking it.
A bad example:
```
The best way to learn WordPress is to start using it. To Download WordPress, click here.
```
A better example:
```
Download WordPress and start using it. That's the best way to learn.
```
## Style Links with Underlines
By default, browsers underline links to let the user know what is clickable. Some designers use CSS to turn off underlines for hyperlinks. This causes usability and accessibility problems, as it makes it more difficult to identify hyperlinks from the surrounding text.
## Different Link Colors
Color is another visual cue that text is clickable. Styling hyperlinks with a different color than the surrounding text makes them easier to distinguish.
Hyperlinks are one of the few HTML features that have state. The two most important states are *visited* and *unvisited*.
Having different colors for these two states helps users identify the pages they’ve visited before. A good trick for taking the guess work out of visited links is to color them 10%-20% darker than the unvisited links.
There are 3 other states that links can have:
- hover, when a mouse is over an element
- focus, similar to hover but for keyboard users
- active, when a user is clicking on a link
Since hover and focus have similar meanings, it is useful to give them the same styles.
Though hover and focus have similar meanings, they have different interaction patterns. If you choose a subtle hover state, you should have a more easily identifiable focus state. Hovering over a link is a directed activity, where the user knows where they are in the page and only needs to identify whether that spot is linked. Focus is an undirected activity, where the user needs to discover where their focus has moved to after shifting focus from the previous location.
## Color Contrast
Color contrast refers to the **difference between two colors**. Contrast is low between navy blue and black. Contrast is high between white and black. WebAIM, a non-profit web accessibility organization, provides a [color contrast calculator](https://webaim.org/resources/contrastchecker/) to help you determine the contrast in your website design. The WCAG 2.0 requires a ratio of 4.5:1 on normal text to be [AA compliant](http://www.w3.org/WAI/WCAG20/quickref/#qr-visual-audio-contrast-contrast).
## Sufficient Font Size
Make your text easy to read. By making your text large enough, you increase the usability of your site and make the content easier to understand. 14px is the smallest text should be.
## Associate Labels with Inputs
Labels inform the user what an input field is for. You can connect the label to the input by using the `for` attribute in the label. This will allow the user to click the label and focus on the input field.
```
```
Labels work for radio buttons as well. Since it works using the **id** field *and not the name*, each input for the group gets its own label.
```
```
## Placeholder Text in Forms
Placeholder text shows the user an example of what to type. When a user puts their cursor in the field, the placeholder text will disappear, while the label remains.
```
```
Use placeholders to suggest the type of data a field requires, and not as a substitute for the field label.
## Descriptive Buttons
The web is filled with buttons that have unclear meanings. Remember the last time you used ‘OK’ or ‘submit’ on your login form? Choosing better words to display on your buttons can make your website easier to use. Try the pattern *\[verb\] \[noun\]* — Create user, Delete File, Update Password, Send Message. Each describes what will happen when the user clicks the button.
---
# JavaScript Best Practices
Source: https://developer.wordpress.org/themes/advanced-topics/javascript-best-practices/
Many themes use JavaScript to provide interactivity, animation or other enhancements. These best practices will help ensure your code works efficiently and does not cause conflicts with your content or plugins.
## Use Included Libraries
There are many useful JavaScript libraries you may want to include when building your theme. Did you know that WordPress comes bundled with dozens of popular libraries? Check out this [list of default scripts included with WordPress](https://developer.wordpress.org/themes/basics/including-css-javascript/#default-scripts-included-and-registered-by-wordpress).
A common mistake made by beginning theme and plugin developers is to bundle their theme or plugin with their own version of the library. This may conflict with other plugins that enqueue the version bundled with WordPress. As a best practice, make your theme compatible with the version of your favorite library included with WordPress.
Do not try to use your own version of a JavaScript library that is already [bundled](https://developer.wordpress.org/themes/basics/including-css-javascript/#default-scripts-included-and-registered-by-wordpress "Default Scripts Included with WordPress") with WordPress. Doing so may break core functionality and conflict with plugins.
If you feel you MUST replace the WordPress version with one of your own… well… the answer is still: don’t do it. The versions of JavaScript libraries used by WordPress may include custom tweaks that WordPress needs to operate. Any time you override these libraries, you risk breaking your WordPress instance. Moreover, plugins created by other authors should be written to be compatible with WordPress’s version of these libraries as well. Adding your own version may (and often does!) conflict with plugins.
## Standard JavaScript
Javascript is growing in popularity for web developers, and it’s being used to accomplish for a variety of tasks. Here are some best practices to use when writing your JavaScript
- Avoid Global Variables
- Keep your JavaScript unobtrusive
- Use closures and the [module pattern](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
- Stick to a coding style. Use The [WordPress Javascript Coding Standard](https://make.wordpress.org/core/handbook/coding-standards/javascript/).
- Validate and Lint Your Code – [E](http://JSLint.com)[S](http://JSLint.com)[Lint.com](https://eslint.org/)
- Ensure your site still works without JavaScript first – then add JavaScript to provide additional capabilities. This is a form of [Progressive Enhancement](http://en.wikipedia.org/wiki/Progressive_enhancement).
- Lazy load assets that aren’t immediately required.
- Don’t use jQuery *if you don’t need to* — There’s a great site that shows you how to do some common tasks with plain old JavaScript – [you might not need jQuery](http://youmightnotneedjquery.com)
## jQuery
### Including jQuery in your theme
[jQuery](http://www.jquery.com) is a popular JavaScript library to make working with JavaScript easier and more reliable across browsers. If you use jQuery, be sure to [follow the handbook guidelines on including JavaScript](https://developer.wordpress.org/themes/basics/including-css-javascript/). Giving your theme’s enqueued .js files a dependency array of `array( 'jquery' )` ensures that the jQuery script has been downloaded and loaded before your theme’s code.
#### Using $
Because the copy of jQuery included in WordPress loads in `noConflict()` mode, use this wrapper code in your theme’s .js files to map “$” to “jQuery”:
```javascript
( function( $ ) {
// Your code goes here
} )( jQuery );
```
This wrapper (called an Immediately Invoked Function Expression, or IIFE) lets you pass in a variable—jQuery—on the bottom line, and give it the name “$” internally. Within this wrapper you may use `$` to select elements as normal.
### Selectors
Every time you select an element with jQuery, it performs a query through your document’s markup. These queries are very fast, but they do take time—you can make your site respond faster by re-using your jQuery objects instead of using a new query. So instead of repeating selectors:
```javascript
// Anti-pattern
$('.post img').addClass('theme-image');
$('.post img').on('click', function() { ... });
```
it is recommended to **cache your selectors** so you can re-use the returned element without having to repeat the lookup process:
```javascript
var $postImage = $('.post img');
// All image tags within posts can now be accessed through $postImage
$postImage.addClass('theme-image');
$postImage.on('click', function() { ... });
```
### Event Handling
When you use jQuery methods like `.bind` or `.click`, jQuery creates a new browser event object to handle processing the requested event. Each new event created takes a small amount of memory, but the amount of memory required goes up the more events you bind. If you have a page with a hundred anchor tags and wanted to fire a `logClick` event handler whenever a user clicked a link, it is very easy to write code like this:
```javascript
// Anti-pattern
$('a').click( logClick );
```
This works, but under the hood you have asked jQuery to create a new event handler for every link on your page.
**Event delegation** is a way to accomplish the same effect with less overhead. Because events in jQuery “bubble”—that is, a click event will fire on a link, then on the link’s surrounding `` tag, then on the `div` container, and so on up to the `document` object itself—we can put a single event handler higher up in the page structure, and still catch the click events for all of those links:
```javascript
// Bind one handler at the document level, which is triggered
// whenever there is a "click" event originating from an "a" tag
$(document).on('click', 'a', logClick);
```
---
# Plugin API Hooks
Source: https://developer.wordpress.org/themes/advanced-topics/plugin-api-hooks/
A theme should work well with WordPress plugins. Plugins add functionality by using actions and filters, which are collectively called hooks (see [Plugin API](https://codex.wordpress.org/Plugin_API "Plugin API") for more information).
Most hooks are executed internally by WordPress, so your theme does not need special tags for them to work. However, a few hooks need to be included in your theme templates. These hooks are fired by special Template Tags:
[wp\_head()](https://developer.wordpress.org/reference/functions/wp_head/ "Function Reference/wp head")Goes at the end of the <head> element of a theme’s *header.php* template file.[wp\_body\_open()](https://developer.wordpress.org/reference/functions/wp_body_open/ "Function Reference/wp head")Goes at the begining of the <body> element of a theme’s *header.php* template file.[wp\_footer()](https://developer.wordpress.org/reference/functions/wp_footer/ "Function Reference/wp footer")Goes in *footer.php*, just before the closing </body> tag.[wp\_meta()](https://developer.wordpress.org/reference/functions/wp_meta/ "Function Reference/wp meta")Typically goes in the <li>Meta</li> section of a Theme’s menu or sidebar.[comment\_form()](https://developer.wordpress.org/reference/functions/comment_form/ "Function Reference/comment form")Goes in *comments.php* directly before the file’s closing tag (</div>).Take a look at a core theme’s templates for examples of how these hooks are used.
---
# Required Theme Files
Source: https://developer.wordpress.org/themes/releasing-your-theme/required-theme-files/
**Block theme:** See [Create a Block Theme](https://developer.wordpress.org/block-editor/how-to-guides/themes/create-block-theme/) for building a block theme
Classic themes must include the required theme files. These files must follow template file standards set by the themes team. For Classic themes, additional standard template files are recommended to use. Learn more about the [Organizing Theme Files](https://developer.wordpress.org/themes/basics/organizing-theme-files/).
## Classic Themes Required Theme Files
1. **style.css** Your theme’s main [stylesheet](https://developer.wordpress.org/themes/basics/including-css-javascript/) file. This file will also include information about your theme, such as author name, version number, and plugin URL, in it’s header.
2. **index.php** The main [template](https://developer.wordpress.org/themes/basics/template-files/) file for your theme. This will be the template for the homepage on your site unless a static front page is specified. If you *only* include this template file, it must include all functionality of your theme. However, you can use as many relevant template files as you want in your theme.
3. ****comments.php**** The comment template which is included wherever comments are allowed. This file should provide support for threaded comments and trackbacks, and should style author comments differently then user comments. See the [Comments](https://developer.wordpress.org/themes/functionality/comments/) page for more information.
4. **screenshot** In the WordPress.org theme directory, the screenshot acts as a visual indicator of what your theme looks like. It is visible both in the web view and in the admin dashboard. The screenshot must not be bigger than 1200 x 900px.
While these files are the only files required by the theme review team for acceptance into the WordPress.org theme directory, you may use other template files. Of course, any file mentioned in the tutorial in this handbook may be used in your theme.
---
# Testing
Source: https://developer.wordpress.org/themes/releasing-your-theme/testing/
If you’ve followed this handbook, you’ll already have a good grasp on the testing required before submitting your theme to the WordPress.org theme directory. If you haven’t, this page will give you a quick refresher.
Testing is incredibly important before releasing a theme. You may have built the most beautiful WordPress theme, but if it breaks when someone tries to comment or insert an image, your theme isn’t ready for real world usage.
Before testing your theme, make sure you’ve setup a development environment. There are a number of ways to setup your environment, many of which are documented on the [Setting up a Development Environment](https://developer.wordpress.org/themes/getting-started/setting-up-a-development-environment/) page.
## Theme Unit Test
After you’ve setup your development environment, you’ll need test content to test your theme with. While you can create your own test content, the theme review team has created the [Theme Unit Test](https://codex.wordpress.org/Theme_Unit_Test), which includes many different types of content. This will help ensure that your theme works in circumstances you may not have anticipated.
The Theme Unit Test is a WordPress export file that can be imported into any WordPress installation by using the WordPress Importer. You should import it into your local development environment.
## WordPress Settings
Making tweaks and changes to your WordPress installation is another good way to ensure that you’ve built your theme to handle numerous scenarios. Use the following settings to test your theme.
**General**
Set the Site Title to something long and set the Tagline to something even longer. These settings will test how your theme handles edge cases for site titles and taglines.
**Reading**
Set “Blog pages show at most” to 5. This setting will ensure that index/archive pagination is triggered.
**Discussion**
Enable “Threaded Comments” at least 3 levels deep. This setting will facilitate testing of your theme’s comment list styling.
Enable “Break comments into pages” and set 5 comments per page to test the pagination and styling of comments.
**Media**
Remove the values for the large size of media to test the theme’s `$content_width` setting.
**Permalinks**
Change the permalink setting a few times to ensure your theme can handle various URL formats.
For more setup instructions, take a look at the [Theme Unit Test](https://codex.wordpress.org/Theme_Unit_Test#Setup) page in the WordPress Codex.
## WordPress Beta Tester
WordPress releases happen three times a year. It’s a good idea to test your theme against the next version of WordPress so you can anticipate issues when the next version is released. This can be done easily with the [WordPress Beta Tester](https://wordpress.org/plugins/wordpress-beta-tester/) plugin. The plugin makes it easy to download either the latest nightly version of WordPress or the latest branch version (for minor bugfix releases). This is especially useful when anticipating a new major release or developing for an upcoming feature.
## Testing and debugging tools
### Theme Check
Each theme goes through an automated check before a reviewer even sees it. If there are any immediate problems with the theme, identified by the automated check, the theme will be rejected with notes on how to resolve the issues. The [Theme Check](https://wordpress.org/plugins/theme-check/) plugin adds a dashboard link under Appearance so you can run the exact same checks that WordPress.org does right from your administration panel. Doing this prior to uploading your theme lets you know what needs to be addressed prior to submission. Running the check will give you a list of any warnings your theme has generated and what items are required for the theme to be accepted in the WordPress.org theme directory, as well as any recommended items that may be missing from your theme.
### Developer
The [Developer](https://wordpress.org/plugins/developer/) plugin is really just a tool to automatically download and install some of the plugins you’ll want when developing your theme. Some of the ones discussed in this handbook will already be installed and active. Others you can install as soon as you activate the plugin.
### Debug Bar
[Debug Bar](https://wordpress.org/plugins/debug-bar/) pushes all debug messages to a separate page where they are listed in an easy-to-read layout and organized by type of message. There are also a number of [other plugins](https://wordpress.org/plugins/search.php?q=debug+bar) that add on to Debug Bar, extending its features or adding more information.
### Log Deprecated Notices
[Log Deprecated Notices](https://wordpress.org/plugins/log-deprecated-notices/) displays a list of the deprecated function notices in your theme and where the code can be found. This should be run, at minimum, after every major release of WordPress, so you can resolve and remove any deprecated code and functions from your theme.
### Browser testing
When submitting your theme to WordPress.org, it’s expected that it works well in modern browsers and at any resolution. You should test your theme against a number of popular browsers before submitting, both mobile and desktop. Many browsers have built-in features making it easy to test, for example the [Chrome Developer Tools](https://developer.chrome.com/devtools), [Firefox Developer Tools](https://developer.mozilla.org/en-US/docs/Tools), and the [Microsoft Edge tools](http://dev.modern.ie). Note that [Internet Explorer is no longer supported by WordPress](https://make.wordpress.org/core/2021/04/22/ie-11-support-phase-out-plan/) since 5.8 release.
### Validation
Likewise, your theme should use valid HTML5 and CSS code. There are a variety of tools that will test your site for valid code, include [this HTML5 validator](http://html5.validator.nu/) and [this CSS validator](http://jigsaw.w3.org/css-validator/).
---
# Theme Review Guidelines
Source: https://developer.wordpress.org/themes/releasing-your-theme/theme-review-guidelines/
The [WordPress Themes Team](https://make.wordpress.org/themes "https://make.wordpress.org/themes") provides and maintains the theme review guidelines as part of their task as WordPress Contributors and Developers for the [WordPress Theme Directory](https://wordpress.org/themes/). Some of these guidelines are required before themes are included in the theme directory. Other guidelines are recommendations for best practices in developing your theme and making it available to as many people as possible. This handbook uses both recommendations and requirements from the theme review guidelines to ensure the theme you develop is accessible to everyone.
The requirements for being included in the WordPress.org theme directory can be found [here](https://make.wordpress.org/themes/handbook/review/required/).
## Get Involved
The WordPress Themes Team is [open to anyone](https://make.wordpress.org/themes/handbook/get-involved/become-a-reviewer/) and is a great way to get a better understanding of how themes are developed. To become a member of the WordPress Themes Team, read through the [WordPress Themes Team’s site](https://make.wordpress.org/themes/).
---
# Writing Documentation
Source: https://developer.wordpress.org/themes/releasing-your-theme/writing-documentation/
Documentation is important for themes as it provides a way for users to understand what a theme does and does not support. Likewise, documenting the code of your theme will make it easier for other theme developers to customize your theme, likely with a [child theme](https://developer.wordpress.org/themes/advanced-topics/child-themes/).
Here’s a list of **requirements** and **recommendations** for your theme’s documentation.
- Themes are **required** to provide end-user documentation of any design limitations or extraordinary installation/setup instructions.
- Themes are **required** to include a [readme.txt file](https://wordpress.org/plugins/about/readme.txt), using the plugin directory’s readme.txt markdown format. New themes need to follow this rule as of October 25th, 2018. Old themes have a 6 months grace time from this date. Since WordPress 5.8 theme [readme files are not parsed for requirements](https://core.trac.wordpress.org/ticket/48520). This means that headers `Requires PHP` and `Requires at least` are going to be parsed from theme’s `style.css` file.
---
# Submitting Your Theme to WordPress.org
Source: https://developer.wordpress.org/themes/releasing-your-theme/submitting-your-theme-to-wordpress-org/
Before themes are added to the WordPress Theme Directory, they are closely reviewed by the [Themes team](https://make.wordpress.org/themes/) to make sure they adhere to basic [guidelines](https://make.wordpress.org/themes/handbook/review/required/). This review ensures that WordPress users across the globe can download themes that are high quality and secure.
## Need Help?
If you have theme development questions, please post them in the [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/) forum. Volunteers from around the world are ready to assist you with the development of your theme.
## Guidelines
Make sure you review the [Theme Review Guidelines](https://make.wordpress.org/themes/handbook/review/required/) before uploading a theme. If you have questions about these guidelines, you can ask them in the [\#themes](https://wordpress.slack.com/messages/themes) channel in [Slack](https://chat.wordpress.org/). Anyone with a WordPress.org account can access the Making WordPress Slack.
## Testing With Sample Data
The [WordPress Themes Team](https://make.wordpress.org/themes/) will be reviewing your theme using the sample data from the [Theme Unit Test](https://developer.wordpress.org/themes/release/testing/). Before uploading your theme for review, please test it with this sample export data.
## Uploading Your Theme
When you are ready to submit your theme for review, please upload your theme ZIP at [Themes > Upload](https://wordpress.org/themes/getting-started/). Future updates are to be uploaded via the same page.
More information about the theme review process is available on the [Themes Team website](https://make.wordpress.org/themes/handbook/review/).
---
# Template Files
Source: https://developer.wordpress.org/themes/basics/template-files/
Template files are used throughout WordPress themes, but first let’s learn about the terminology.
## Template Terminology
The term “template” is used in different ways when working with WordPress themes:
- Templates files exist within a theme and express how your site is displayed.
- [Template Hierarchy](https://developer.wordpress.org/themes/basics/template-hierarchy/) is the logic WordPress uses to decide which theme template file(s) to use, depending on the content being requested.
- [Page Templates](https://developer.wordpress.org/themes/template-files-section/page-template-files/ "Page Templates") are those that apply to pages, posts, and custom post types to change their look and feel.
**In classic themes,** [Template Tags](https://developer.wordpress.org/themes/basics/template-tags/ "Template Tags") are built-in WordPress functions you can use inside a template file to retrieve and display data (such as [`the_title()`](https://developer.wordpress.org/reference/hooks/the_title/ "Function Reference/the title") and [`the_content()`](https://developer.wordpress.org/reference/hooks/the_content/ "Function Reference/the content")).
**In block themes,** blocks are used instead of template tags.
## Template files
WordPress themes are made up of template files.
- In classic themes these are PHP files that contain a mixture of HTML, [Template Tags](https://developer.wordpress.org/themes/basics/template-tags/ "Template Tags"), and PHP code.
- In block themes these are HTML files that contain HTML markup representing blocks.
When you are building your theme, you will use template files to affect the layout and design of different parts of your website. For example, you would use a `header` template or template part to create a header.
When someone visits a page on your website, WordPress loads a template based on the request. The type of content that is displayed by the template file is determined by the [Post Type](https://developer.wordpress.org/themes/basics/post-types/) associated with the template file. The [Template Hierarchy](https://developer.wordpress.org/themes/basics/template-hierarchy/ "Template Hierarchy") describes which template file WordPress will load based on the type of request and whether the template exists in the theme. The server then parses the code in the template and returns HTML to the visitor.
The most critical template file is `the index`, which is the catch-all template if a more-specific template can not be found in the [template hierarchy](https://developer.wordpress.org/themes/basics/template-hierarchy/). Although a theme only needs a `index` template, typically themes include numerous templates to display different content types and contexts.
## Template partials
A template part is a piece of a template that is included as a part of another template, such as a site header. Template part can be embedded in multiple templates, simplifying theme creation. Common template parts include:
- `header.php` or `header.html` for generating the site’s header
- `footer.php` or `footer.html` for generating the footer
- `sidebar.php` or `sidebar.html` for generating the sidebar
While the above template files are special-case in WordPress and apply to just one portion of a page, you can create any number of template partials and include them in other template files.
In block themes, template parts must be placed inside a folder called parts.
## Common WordPress template files
Below is a list of some basic theme templates and files recognized by WordPress.
**index.php (classic theme) or index.html (block theme)**
The main template file. It is **required** in all themes.
**style.css**
The main stylesheet. It is **required** in all themes and contains the information header for your theme.
**rtl.css**
The right-to-left stylesheet is included automatically if the website language’s text direction is right-to-left.
**front-page.php (classic theme) or front-page.html (block theme)**
The front page template is always used as the site front page if it exists, regardless of what settings on **Admin > Settings > Reading**.
**home.php (classic theme) or home.html (block theme)**
The home page template is the front page by default. If you do not set WordPress to use a static front page, this template is used to show latest posts.
**singular.php (classic theme) or singular.html (block theme)**
The singular template is used for posts when `single.php` is not found, or for pages when `page.php` are not found. If `singular.php` is not found, `index.php` is used.
**single.php (classic theme) or single.html (block theme)**
The single post template is used when a visitor requests a single post.
**single-{post-type}.php (classic theme) or single-{post-type}.html (block theme)**
The single post template used when a visitor requests a single post from a custom post type. For example, `single-book.php` would be used for displaying single posts from a custom post type named *book*.
**archive-{post-type}.php (classic theme) or archive-{post-type}.html (block theme)**
The archive post type template is used when visitors request a custom post type archive. For example, `archive-books.php` would be used for displaying an archive of posts from the custom post type named *books*. The archive template file is used if the `archive-{post-type} template` is not present.
**page.php (classic theme) or page.html (block theme)**
The page template is used when visitors request individual pages, which are a built-in template.
**page-{slug}.php (classic theme) or page-{slug}.html (block theme)**
The page slug template is used when visitors request a specific page, for example one with the “about” slug (page-about.php).
**category.php (classic theme) or category.html (block theme)**
The category template is used when visitors request posts by category.
**tag.php (classic theme) or tag.html (block theme)**
The tag template is used when visitors request posts by tag.
**taxonomy.php (classic theme) or taxonomy.html (block theme)**
The taxonomy term template is used when a visitor requests a term in a custom taxonomy.
**author.php (classic theme) or author.html (block theme)**
The author page template is used whenever a visitor loads an author page.
**date.php (classic theme) or date.html (block theme)**
The date/time template is used when posts are requested by date or time. For example, the pages generated with these slugs:
http://example.com/blog/2014/
http://example.com/blog/2014/05/
http://example.com/blog/2014/05/26/
**archive.php (classic theme) or archive.html (block theme)**
The archive template is used when visitors request posts by category, author, or date. **Note**: this template will be overridden if more specific templates are present like `category.php`, `author.php`, and `date.php`.
**search.php (classic theme) or search.html (block theme)**
The search results template is used to display a visitor’s search results.
**attachment.php (classic theme) or attachment.html (block theme)**
The attachment template is used when viewing a single attachment like an image, pdf, or other media file.
**image.php (classic theme) or image.html (block theme)**
The image attachment template is a more specific version of `attachment.php` and is used when viewing a single image attachment. If not present, WordPress will use `attachment.php` instead.
**404.php (classic theme) or 404.html (block theme)**
The 404 template is used when WordPress cannot find a post, page, or other content that matches the visitor’s request.
**comments.php**
The comments template in classic themes. In block themes, blocks are used instead.
## Using template files
### Classic themes
In classic themes, within WordPress templates, you can use [Template Tags](https://developer.wordpress.org/themes/basics/template-tags/ "Template Tags") to display information dynamically, include other template files, or otherwise customize your site.
For example, in your `index.php` you can include other files in your final generated page:
- To include the header, use [get\_header()](https://developer.wordpress.org/reference/functions/get_header/ "Function Reference/get header")
- To include the sidebar, use [get\_sidebar()](https://developer.wordpress.org/reference/functions/get_sidebar/ "Function Reference/get sidebar")
- To include the footer, use [get\_footer()](https://developer.wordpress.org/reference/functions/get_footer/ "Function Reference/get footer")
- To include the search form, use [get\_search\_form()](https://developer.wordpress.org/reference/functions/get_search_form/ "Function Reference/get search form")
- To include custom theme files, use [get\_template\_part()](https://developer.wordpress.org/reference/functions/get_template_part/ "Function Reference/get template part")
Here is an example of WordPress template tags to *include* specific templates into your page:
```php
```
There’s an entire page on [Template Tags](https://developer.wordpress.org/themes/basics/template-tags/ "Template Tags") that you can dive into to learn all about them.
Refer to the section [Linking Theme Files & Directories](https://developer.wordpress.org/themes/basics/linking-theme-files-directories/ "Linking Theme Files & Directories") for more information on linking component templates.
### Block themes
In block themes you use blocks instead of template tags. Block markup is the HTML code that WordPress uses to display the block. Template parts are blocks, and you add them to your template files the same way as you add blocks.
To include a header or footer template part, add the block markup for the template part. The `slug` is the name of the part. If the file you want to include is called `header.html`, then the slug is “header”:
```markup
(your page content)
```
To include the search form, use the block markup for the search block:
```markup
```
---
# Reworking Theme Files & Organization
Source: https://developer.wordpress.org/themes/basics/reworking-theme-files-organization/

## Theme folder and file structure
While WordPress themes technically only require two files (`index.php` and `style.css`), they usually are made up of many files and can become quickly disorganized.
In the last section, [Template Files](# "Template Files"), you set up your `header.php, footer.php, page.php, home.php, and single.php` files.
Let’s look at the [Twenty Twelve theme](https://wordpress.org/themes/twentytwelve) default themes as one example of good file structure and organization. While this may be a bit overwhelming at first, let’s break it down. Can you find the templates you just built?

While there are still a lot of files, their names help provide a context of what they are. Basically each file handles a feature of WordPress. I.e. `comments.php` deals with how the theme will handle comments; `image.php` instructs the theme how to handle images, etc. Don’t worry about adding these files unless you need them.
You can see that the main theme template files are in the theme’s root directory, while JavaScript, languages, CSS, and page template files are placed within their own folders.
At this time there are **no required folders within a WordPress theme**. However, WordPress does recognize the following folders by default:
### Page templates folder

The [custom page templates](https://developer.wordpress.org/themes/basics/page-templates/ "Custom Page Templates"), named *page-templates* (since: 3.4.0) allows for better organization of template files. Custom page template files placed in this folder are automatically recognized by WordPress.
### Language folder

If you wish to [internationalize your theme](https://developer.wordpress.org/themes/functionality/internationalization/ "Internationalization") so it’s usable in other languages, you can create a *languages* folder to contain translations.
---
# Updating Your Theme
Source: https://developer.wordpress.org/themes/releasing-your-theme/updating-your-theme/
There are two ways to update your theme, by uploading a Zip file or using subversion (SVN).
## Uploading a Zip file
While your theme is in the queue and waiting for review, you can update your theme by [uploading a Zip file](https://wordpress.org/themes/getting-started/). Just as you initially uploaded. Be sure to update the version number on style.css before uploading.
Updating the version number will NOT change the queue position of your theme while waiting for the review.
If you already have your themes in the repository, you can either update by uploading a Zip file or via SVN.
## Subversion GUI clients
Several GUI clients are available for Windows users. [TortoiseSVN](https://tortoisesvn.net/) is one of the popular Free clients. [SmartSVN](https://www.smartsvn.com/) is a paid application that works on Windows, Linux, and macOS.
For Mac users, SVN helps streamline the automation process, including removing `.DS_Store` and `__MACOSX` hidden files and folders that often trigger the theme check errors.
### Important notes:
**(1) Directory naming guidelines**
The theme author must create a new directory before uploading the theme. It is important to name the new directory with the new version number. For example, if the current theme is version `1.0.1`, the name for the new directory must be *`1.0.2`*.
**(2) Version numbering**
Version numbering must follow a standard version naming convention. New version must be higher than the current version. For example, if your current theme is `1.2.3`, the new version must be `1.2.4`.
**(3) SVN is not a development tool**
Unlike Github, SVN is not a development tool. You should upload your theme only when you are ready to release a new version. Once you commit, the changes cannot be overwritten. If you find a mistake, even a small typo, there is no way to make changes. The only way to make corrections is to create another directory with a newer version number and upload it again.
### Uploading your themes using SVN on MacOS
**What you will need**
- MacOS
- VS code
- SVN extension for VS code
To check whether you have svn installed, type `svn --version` in the terminal.
(1) Create a copy of the repository on your local machine. Replace */NameOfYourTheme/* with your theme name. `svn co https://themes.svn.wordpress.org/NameOfYourTheme/`
For example, if your theme name is Hello World,
use `svn co https://themes.svn.wordpress.org/hello-world/`
**Tips:** If you are not sure about the exact name of your theme (e.g. hyphen, underscore), you can find it at [this link](https://themes.svn.wordpress.org/).
(2) The next step is to create a new directory and copy all theme files, including the history from the current version of the theme. In the example below, we are creating a new directory 1.0.2, and copying all files from the version 1.0.1. `svn cp 1.0.1 1.0.2`
(3) Make changes to your theme.
**Note:** Make sure to update the version number on style.css, and the changelog on readme.txt
(4) Remove *.DS\_Store* hidden file. `find . -name ".DS_Store" -print -delete`
(5) Next, remove `__MACOSX` folder. `rm -R __MACOSX`
(6) Finally, you are ready to commit.
`svn commit -m “Fix typo on readme.txt”`
**Note:** Once you commit, there is no way to change or modify what you just committed. If you find a mistake, Repeat the process from step 2.
### What to expect next
Once you successfully upload the new update, you will receive a confirmation email from WordPress.org. It may take some time to reflect on the WordPress.org directory.
---
# Classic themes
Source: https://developer.wordpress.org/themes/classic-themes/
In this section you will find information about developing classic WordPress themes.
---
# Block theme accessibility
Source: https://developer.wordpress.org/themes/functionality/block-theme-accessibility/
Block themes support accessibility and simplify the process for adding accessibility.
## Landmark
Group, Template part, and Query blocks can become a landmark. There are two ways to create landmark.
**Using block markup**
`”tagName":"header”` creates header landmark.
```
' . get_the_title() . '' ); ?>
'ol', 'short_ping' => true, 'avatar_size' => 74, ) ); ?>
1 && get_option( 'page_comments' ) ) : ?>