Blogger Title Fix


Blogger Title Fix
If you have ever imported a Blogger blog into WordPress you probably have some posts that were originally missing a title. During the import, a title (and post slug) was created for the post that looks like a large numerical value. I believe this is the original Blogger post ID, I guess the importer needed something to use.

What this plugin does is replace those ugly numerical titles with the first few words of your post, like Blogger did. By simply enabling the plugin, any post that matches the “ugly title” filter will have the title replaced by the first 48 characters of the post.

Download
Latest version of the plugin – Release 2.2
Also available from http://wordpress.org/extend/plugins/blogger-title-fix/
Installation

  1. Upload to your plugins folder, usually `wp-content/plugins/`.
  2. Activate the plugin on the plugin screen.
  3. Configure the plugin in the Options admin tab. As of version 2.0 it is now in the Plugins tab.
  4. That’s it

History

  • Revision 0.1 – Initial release
  • Revision 0.2 – Added option to change the number of characters used for the title from the default 48. Added option to break the title at a word boundary.
  • Revision 2.0 – Upgraded to work with WordPress 2.5. Fixed a bug with disabling the word boundary setting. Made it more efficient by removing the extra DB query unless it was really necessary.
  • Revision 2.1 – Added single_post_title filter at the request of Alejandro Carravedo
  • Revision 2.2 – Removed usage of second parameter for the_title filter, it was inconsistent – relies on global “post” to generate the new title.

How it works
It is quite simple really. So simple that I’m surprised no one has done it before given all of the issues people have posted about this problem on the wordpress.org support forums.

This plugin added as a filter for “the_title”. This means that anywhere a title is displayed in the blog it will be filtered by this plugin first. If the title looks like a “missing title from blogger” number (or any string of numerical digits) then the first 48 characters of the post (without any formatting) plus “…” are used as the post title instead of that string. Note that the logic is not very intelligent yet, so any post with only numbers in the title will be treated this way. There are now options to change this behaviour so you can change the number of characters from the default 48 and choose to break the title on word boundaries (this can cause it to go over the maximum length).

The title is constructed much like the way an “excerpt” is built (and the code copied from there) but I could not use the excerpt for various reasons. The biggest reason is when a page needs to show more than one title – the excerpt filter does not take a “post” parameter and uses the global “post” instead. With the “the_title” filter, there is an optional “post” parameter that is used for the extra posts (like previous and next posts on a post page). The code for this plugin is stand-alone and does not use other filters.

Known Issues

It is not very smart about what is considered a good or bad title. Right now any post title that contains only numbers will be filtered. If your blog has real titles that contain only numbers then it will interact poorly with those. Perhaps there is a more restrictive pattern to match (is there a minimum number of characters to the blogger ID?). If anyone knows I would be happy to improve the plugin.

Extra DB query. The extra “post” parameter from the “the_title” filter used for the previous and next links on a post page does not contain the post contents so an extra DB query is needed to get those contents.

It does not change the post slug. The post-slug, or permalink, will remain the numerical code. This isn’t as pretty to email people, and will not be compatible if you are trying to replace Blogger permalinks with WordPress permalinks. I’m not sure if there is a good solution for this and I have not looked into whether a post slug could even be modified by a plugin. For now it will have to be acceptable that the post at least looks good on the site.

48 characters is not exactly correct. Well, it is and it isn’t. From what I can tell of the posts I have imported from Blogger into WordPress, Blogger uses the first 48 characters of the post for the title (and fewer for the slug). However, during the import, some special characters may be replaced in WordPress with their escape sequence. This impacts the number of characters from the start of the post that are used for the title, so the title will appear slighly shorter than Blogger.

Links
Check out my other WordPress Plugin.


CC-GNU GPL
This software is licensed under the CC-GNU GPL.