WordPress 4.1 Improvements for Theme Developers

WordPress 4.1 is bringing with it a couple of cool new additions for theme developers. They’re things that are currently a bit messy to implement in themes. For me they are things that I do the same way in all my themes and so there is a lot of duplication – as such it’s nice to see them added. Below I will go over what has changed – and I will describe how to make use of the updates.

add_theme_support( ‘title-tag’ );

The title tag has been added as a theme feature and implementing it is easy. All you have to do is delete thetag and the reference to wp_title from your themes header.php. You should also remove (or test) any filters you have running on the wp_title hook. For me this is a great little improvement. The current method of adding the wp_title call and then filtering the output so that it is actually nice has always felt a bit messy so having it all added to a single location makes the theme a lot cleaner and means that the function can be maintained by WordPress itself.

Of course filters still work on the output and so plugins like WP SEO can still filter the output according to your requirements.

To add this to your own theme just add the following to your themes functions.php:

function bm_title_tag() {
    // title tag
    add_theme_support( 'title-tag' );
}

add_action( 'after_setup_theme', 'bm_title_tag' );

the_pagination()

Numeric pagination is great for users- it gives a nice quick way to skip through long archives of content. However WordPress has not previously had a native way to add pagination to posts. I wrote a blog post last year about one method of adding pagination using native WordPress functions – but I’ve since found out it’s not perfect so a native method that wraps up that complexity is very welcome.

Basic usage is simple but there’s also a bunch of parameters you can use to edit how the links are output. The basic parameters seem to be the same as for the existing paginate_links function – but they make it’s usage a lot simpler.

the_archive_title()

There are lots of types of Archives in WordPress. You can list posts by date (year, day, month), category, tag, taxonomy, and more. For most people each archive will look the same, but it will need a different title format. The normal method for managing this is to create a huge if then statement with a lot of conditions – but that’s a mess, and isn’t easily filterable. Now the code is a single function call – the_archive_title().

If you want to wrap the title in header tags (or other html) then pass them as parameters – eg:

the_archive_title( '<h1 class="page-title">', '</h1>' );

the_archive_description()

I get the impression that not many people use the category description functionality – but I think it’s a really nice thing to include in a theme and to use on a website. It gives some context to categories and adds additional text to category pages which can help with SEO.

Usage is similar to the_archive_title above – however it replaces less code than the previous function. In my case it only removes a couple of lines – but it’s still nice to have standard methods for these things.

the_archive_description( '<div class="taxonomy-description">', '</div>' );

Wrapping Up

I think it’s good to see some of these common issues being simplified and standardized. Anything that removes code from my themes is good and reduces the burden on theme authors.

To keep up to date with WordPress development you can follow the make core blog – it can be technical but I find I often pick up intereting nuggets like the functions above. To save sifting through loads and loads of content it can be helpful to just look at the week in core summaries. For themes in particular you can also follow the incredibly active _s project on Github.

Was it good/ useful/ a load of old rubbish? Let me know on Mastodon, or BlueSky (or Twitter X if you must).

Link to this page

Thanks for reading. I'd really appreciate it if you'd link to this page if you mention it in your newsletter or on your blog.

WordPress News

The latest WordPress updates from the WPBriefs Podcast.

Related Posts

01 Apr 2015

The State of WordPress Themes #wcldn

I recently spoke on a panel at WordCamp London 2015e. Lance – who used to be the Theme Team lead at WordPress.com – asked me if I wanted to speak on a panel with him at WordCamp London 2015. I’ve...
27 May 2013

WordPress: 10 Years Young, What Does The Future Hold?

WordPress is now 10 years old. I started using wordpress 9 years ago – which means I joined the WordPress community early on. The reason I chose WordPress is simply because of the fabled 5 minute install process – I...
08 Aug 2013

The Death of WordPress Theme Frameworks

WordPress theme frameworks are on their way out. They’re dying a slow death. At least that’s what I think.Nathan Rice recently wrote an article with his thoughts about theme frameworks – in defense of them – however he clearly has...
22 May 2013

11 Things Your Boss Expects You to Know About WordPress

WordPress blogs have become an important tool for promoting businesses. There can be a bit of work involved in maintaining this online presence, and your boss may expect you to get involved – this person may even decide to hand...
13 Oct 2016

Lessons Learned from 20 Theme Releases on WordPress.com

In 2007 I partnered with Darren Hoyt to release Mimbo Pro, one of the earliest premium WordPress themes. In 2012 Mimbo Pro was published on wordpress.com. Last week – on October 5th 2016 to be precise – my 20th theme...