WordPress 4.1 for Theme Developers: Life Became Easier
WordPress 4.1 was a version long waited for by theme developers. Especially for this target audience there is lots of innovation. Not only the new standard theme "Twenty Fifteen" has become available but also several more new functions and features. This new functionality reduces the difficulty of theme development considerably. In the following article, we will look at the new features closely and show you how you can use them in the development process of a new theme.
1. The Automatic Title Tag
Up to the release of WordPress 4.1, every theme had its own implementation of the <title> tag. Every developer went his own way. At times, code varied considerably between themes. Especially this variety of possibilities made it difficult for external plug-ins - such as SEO - to manipulate the content of the title tag. The new and highly recommended approach is using add_theme_support() for the title tag. The necessary code is relatively straightforward: Via notation through theme support WordPress was told that the <title> should be generated automatically. This is done using the function_wp_render_title_tag()
which hooks into wp_head
. The filters of wp_title
can still be used to adjust the display of the title.
Features for Navigation and Pagination
WordPress has contained features for providing navigation links within articles and article outlines for some time now. But every theme used these functions with a different code and text. WordPress 4.1 now for the first time offers tags which layout the whole navigation. This enables theme developers to concentrate on the most important element of all: design. Another advantage of the new navigation tags is that they no longer need to be translated. The right translations are already (almost entirely, at least) available in the WordPress core.2. Post Navigation between Artikels
The two post navigation functionsthe_post_navigation()
and get_the_post_navigation()
provide a solution for linking to the previous and the next article. These functions come into effect while viewing the article (single.php).
The functions accept an array of arguments:
prev_text
: the text of the link to the previous articles, standard being the title of the articlenext_text
: the text for the next articles, standard being the title of the article.screen_reader_text
: the text for screenreaders.
3. Post Navigation between the Pages of the Articles
The two functions presented in 2. can also be used for navigating between single pages of the article overviews (index.php and archives.php). In this case the functions accept an array of the following arguments:prev_text
: the text of the link to the previous article page, standard being "older entries".next_text
: the text for the next article page, standard being "newer entries".screen_reader_text
: the text for screenreaders
4. Post Pagination - Numbered Blog Page Navigation
Post Pagination is an extremely interesting new function as it enables the user to create a complete, paginated navigation with just one tag that is included into the theme file. The new tag can be provided and adjusted with all the arguments of the older tagpaginate_links()
. In the near future, we will have an article for creating a perfectly numbered navigation here on noupe.com. The fact that pagination was possible almost as easily before WordPress 4.1 by using the template tag paginate_links()
is probably well-known.
A selection of arguments for this function:
mid_size
: how many page numbers are displayed beside the current one - defaults to 1prev_text
: the text with links to the previous page - defaults to "previous"next_text
: the text with links to the next page - defaults to "next"screen_reader_text
: text for screenreaders
Functions for Archives
Archives serve an important function within WordPress. WordPress supports taxonomy (categories, tags and post formats) and date archives, such as archives by day, month or year. Moreover, two of the taxonomies support archive descriptions, meaning archives by categories and tags. These functions allow adding a description for each category and each day. It became the best approach for theme developers to display these descriptions together with a fitting archive title on the respective archive pages. WordPress 4.1 introduces new tags to make life easier for developers in this regard, thus helping save time.5. The Archive Title
The two functionsthe_archive_title()
and get_the_archive_title()
show the title of the archive with a fitting prefix, which varies with the type of the displayed archive:
- Category: for category archives
- Tag: for tag archives
- Author: for author archives
- Year:, month: and day: for archives by year, month, and tag
- Asides, gallery, image, video, quote, link, status notifications, audio and chat: for archives by post format.
- Archives: for user-defined archives
get_the_archive_title
filter.
The the_archive_title()
function accepts two arguments, $before and $after. These arguments can be used to display additional text before and behind the archive title.
6. The Archive Descriptions
The two functionsthe_archive_description()
and get_the_archive_description()
are responsible for the display of descriptions of taxonomies. This works for categories, tags, and user-defined taxonomies.
The the_archive_description()
template tag accepts the two arguments $before
and $after
. These arguments can be used to display additional text before and after the description.
7. The Screenreader Text
When using the new template tag, you will soon realize that besides the source code of the functions, a text for screenreaders is automatically added to each function. This is important for the accessibility of your website in the sense of it being barrier-free, as with these additional text elements even visually handicapped users can partake of the content of your websites. The additional text for screenreaders is not supposed to be visible to the world, but only when viewing the source code. You can hide this text quickly from the visible part of your theme with the following CSS, while still maintaining the accessibility for screenreaders:8. - Outdated Admin Menu Links
None other than expected WordPress version 4.1 again uses the word "deprecated". Deprecated marks outdated functions, which though they still work should no longer be used. In version 4.1, the admin menu points for the background drew the short straw. Both menu points are still available under the menu item "Design", but they no longer link to standalone pages (as they did before). Both links forward to the new theme customizer. The standalone links will likely be removed from the menu with the next WordPress version. If you want to add the theme support for the user-defined background, you will no longer need to add the callback functions for theadmin-head-callback
and admin-preview-callback
arguments for add_theme_support('custom-background')
. Everything is solely done via the theme customizer. A wonderful introduction to the theme customizer and the best practices for programming the functions is delivered by the new WordPress standard theme Twenty Fifteen.
Conclusion
The new functions are not dazzling, but in some cases alleviate the work of theme developers considerably. If you want to know more about the new features and the optimal way to use them, I recommend you to take a closer look at the _s (Underscores) starter theme over on Github. It is completely up to date with all new WordPress functions and, in addition, offers support for older versions of WordPress also. I can recommend the new Twenty Fifteen theme as a template for learning new functions without reservations, due to the optimal implementation of all new features.Related Links
- WordPress Standard-Theme Twenty Fifteen
- WordPress Code Reference: the_post_navigation()
- WordPress Code Reference: get_the_post_navigation()
- WordPress Code Reference: the_posts_pagination()
- WordPress Codex: paginate_links()
- WordPress Code Reference: the_posts_pagination()
- WordPress Code Reference: the_archive_title()
- WordPress Code Reference: get_the_archive_title()
- WordPress Code Reference: the_archive_description()
- WordPress Code Reference: get_the_archive_description()
- WordPress Codex: Theme Customization API
- WordPress Starter Theme: _s (Underscores) by Automattic