WordPress Code Snippets

A fresh mix of code snippets and tutorials

WordPress Prefix Post Titles

228

A reader recently asked how they can prepend the post date to the post title. Here is a quick and easy way to do it by filtering WordPress’ the_title hook.

The easiest way to add a prefix to the post title is to use WP’s the_title filter. Here is an example:

function shapeSpace_title_prefix($title, $id = null) {
	return get_the_date() .' : '. $title;
}
add_filter('the_title', 'shapeSpace_title_prefix', 10, 2);

Just add that to your theme’s functions.php and done. Note that instead of using get_the_date() you can use get_the_time(). Or anything else that works as a suitable post-title prefix. Endless possibilities.

Learn more

WordPress Themes In Depth


Show Support

Like our new Facebook Page to show support!