A Remaining Problem with Title-less Posts

When showing title-less posts in the archives, I would prefer to show the first few words of the post rather than nothing. Is there an easy way to do that?

UPDATE 2018-07-15: I ended up making a child theme and hooking into the simple-yearly-archive plugin, which I’m using for the archives page.

The only catch is that the plugin doesn’t include the post content column in the query so I had to edit the actual plugin query to include the column and also pass the entire $post object in the sya_the_title hook. I’ll have to watch out for updates, as they’ll overwrite this. Or I’ll just need to fork it.

add_filter( 'sya_the_title', 'my_sya_filter_title', 10, 2 );

function my_sya_filter_title( $title, $post ) {
	return $title == '' ? jab_truncate(strip_tags($post->post_content)) : $title;

function jab_truncate($string,$length=50,$append="…") {
  $string = trim($string);

  // break at word
  if(strlen($string) > $length) {
    $string = wordwrap($string, $length);
    $string = explode("\n", $string, 2);
    $string = $string[0] . $append;

  return $string;

8 thoughts on “A Remaining Problem with Title-less Posts

  1. @jack ahh but if you install nanopub you can post to your micro.blog from any micro.blog client. I have it set up as its own Hugo install on a server which is aliased into my site structure as a subdirectory. When a new post is made I have incrond run Hugo to generate the micro.blog portion.

  2. @jack I’d consider that a bug in whichever theme you’re using, since that display behavior is defined by the theme.

    Depending on how the theme’s archive page works, it might be fairly simple to fix (e.g., TwentyFifteen’s archive.php delegates the display of posts in the archive to content-postformat.php files, so if all your titleless posts are say, status format, you could add a content-status.php that does the right thing).

    My first step would still be to report it as a bug to the theme’s author, though. I’d think listing titleless posts on archive page should, well, display something that lets you access the post 😛

Leave a Reply

Your email address will not be published. Required fields are marked *