WordPress Single Line Post Title Display

In my last post I discussed how I archived the blog from my .NET years, and even though I migrated it from BlogEngine.NET to WordPress decided to keep it separate from NixMash. Displaying single line post titles is an efficient way to view the contents of an archived blog with over 2000 posts. This post describes how I modified the theme to make that happen.

The blog is located at http://dbvt.com.  Here is a screenshot of the site Home Page with single line post titles.

To make certain a longer post title wouldn’t wrap onto a second line I added truncation logic which we’ll see in a minute. And for any truncated titles I added a simple HREF “title” property to display the full title on mouseover as shown here.

The Code

It’s important to note that everything changed was in the theme files (which is “Path”, by the way), so unless the Path Theme is updated by its author, we’re good for the long run on single line post title display.

We start in the content.php template.

Content.php displays a complete Post object, either on a post list or single post. It makes that determination with the is_singular() function.

We added the circled code above, replacing the theme’s original post content template which displayed title, author, date published and categories. The original template code is shown below.

WordPress Shortcodes

Shortcoding is one of the reasons WordPress is so darn popular. Shortcodes give developers the ability to create detailed and reusable display formats for common and custom data objects. Shown in the code above is multiple calls to apply_atomic_shortcode() which calls the WordPress add_shortcode() function. That happens in the theme’s /library/functions/shortcodes.php file.

Rather than add the logic in the existing Post Title shortcode handler for single line display we added a new shortcode and handler function. First the new shortcodes.php add_shortcode() call.

Here the single_line_entry_title_shortcode() shortcode handler and supporting the_single_line_title() function where we perform the truncation check.

And shown again for completeness, here is the resulting single line title display. If you don’t believe me you can see it live at DBVT.com.