WordPress

New Functions Available In WordPress 4.1

In this article we are going to have a look at some of the new features and functions that are available to WordPress developers in version 4.1.

Auto-generated Title Tag

In previous versions of WordPress the theme developer will need to implement their own version of the HTML title tag which you would do using the function wp_title().

<title>
<?php wp_title( '|', true, 'right' ); ?>
</title>

Now with WordPress 4.1 the title tag can now be auto-generated by using the theme support title-tag.

add_theme_support( 'title-tag' );

This means you can now remove the HTML title tag from your theme as it will be added by the wp_head() function. When this setting is set in your theme functions.php it will run the function _wp_render_title_tag(), which will run inside the wp_head() function and echo out the return of the old wp_title() function.

/**
 * Display title tag with contents.
 *
 * @since 4.1.0
 * @access private
 * @internal
 *
 * @see wp_title()
 */
function _wp_render_title_tag() {
	if ( ! current_theme_supports( 'title-tag' ) ) {
		return;
	}

	// This can only work internally on wp_head.
	if ( ! did_action( 'wp_head' ) && ! doing_action( 'wp_head' ) ) {
		return;
	}

	echo '<title>' . wp_title( '|', false, 'right' ) . "</title>\n";
}

Single Post Navigation

In previous versions of WordPress there are functions that allow you to define both the previous and next post functions that can be used in the single.php theme. These functions are get_previous_posts_link() and get_next_posts_link().

echo get_previous_posts_link();
echo get_next_posts_link();

With WordPress 4.1 you can combine these into one function the_post_navigation() allowing the developer to just worry about the styling of the output.

the_post_navigation( $args );

This function will call and echo get_the_post_navigation(), which takes the arguments

  • prev_text - Text to use on the previous link.
  • next_text - Text to use on the next link
  • screen_reader_text - Text to be used for screen readers.

List Post Navigation Pagination

In previous versions of WordPress there are ways to auto generate pagination links by using the function paginate_links() which you can find out more how to use this function with the following tutorial Create Your Own Pagination Links.

This can now be replaced with the function get_the_posts_pagination() or the_posts_pagination(), passing in the arguments

  • mid_size - Define how many pages to display either side of the current page
  • prev_text - Text to use on the previous link
  • next_text - Text to use on the next link
  • screen_reader_text - Text to use on screen readers
the_posts_pagination();

Archive Titles

There are many different types of archive pages that you can get in WordPress

  • Category
  • Tag
  • Author
  • Year
  • Month
  • Day
  • Taxonomy

Using the new function the_archive_title() WordPress will display the correct title for the type of page.

If on a category page it will display a title of Category: {CATEGORY_NAME}, if on an author page it will display the title Author: {AUTHOR_NAME}.

Simply by using the function

the_archive_title( $prefixTitle, $afterTitle );

Along with the archive title there is now the function the_archive_description() which will display the term_description with a prefix and after variable.

the_archive_description( $prefixDescription, $afterDescription )
Back to top

Fastest WordPress Hosting With WPEngine

Stunning speed, powerful security, and best-in-class customer service. At WP Engine.

Risk free for 60 days