Building a WordPress Series Plugin: Title Formatting

By Sol in Lab

I had planned to continue working on advanced series management today, but I switched gears and decided to focus on rounding out core functionality first.

Today, I focused on title formatting.

The Catalyst

Here’s the thing, in the past, whenever I created multiple posts for a single topic (i.e. a series), I manually prefixed each post’s title with the title of the series. Besides creating several potential issues (typos in series title, different formatting, etc.), this is tedious. I have a seriously low tolerance for repetition, so this was a major pain point for me and was ultimately the catalyst for starting work on this plugin.

Maybe that should be my mantra for WordPress plugins:

Find the pain and plug it.

Sorry, sorry, bad pun, I know.

And yet…

The Bottom Line

Just as a link to its series is added to a post’s content, the title of its series should be automatically added to a post’s title in the appropriate places.

Title Types

Here are the different incarnations of post titles and their default formatting. Of course, all formatting can be enabled, disabled, and customized by the user.

Post title

The post title is used everywhere throughout the site. The series title will almost always be added to the post’s title.

Conditions

  • General (sitewide): {{series_title}}: {{post_title}}
  • Single (item’s own page): {{series_title}}: {{post_title}}
  • Series Listing (shortcode/widget): {{post_title}}

Post title attribute

The post title attribute is nearly as prevalent as the post title itself, though it’s rarely visible to the end user as it is mostly used as the title attribute for links to the post. Formatting this value improves accessibility and creates consistency throughout the site.

Conditions

  • General (sitewide): {{series_title}}: {{post_title}}
  • Series Listing (shortcode/widget): {{post_title}}

Site title (in document head)

The site’s title is what you see in the browser’s title bar. This will only need to be formatted on a post’s own page. Other plugins (e.g. WP SEO) may modify the site title, so we need to account for this as well.

Conditions

  • Single (item’s own page): {{series_title}}: {{post_title}}

Feed Items

A site’s content is also accessed via RSS, so the titles of posts in feeds need to be formatted as well. Users will also be able to subscribe to a specific series, so the title should be appropriately formatted for these feeds as well.

Conditions

  • General (standard feeds): {{series_title}}: {{post_title}}
  • Series feed: {{post_title}}