Feature Request: in Post Title block with empty post title, print a placeholder title
What problem does this address?
When using the Post Title block, if a published post has no title, the rendered block is empty.
This is problematic when used with isLink in the Query Loop as there is no way for the reader to click through to the post.
What is your proposed solution?
In a classic theme, this was usually taken into account by placing the post link on the date, or by printing a placeholder No Title / Untitled or such like, if said post had no title.
An idea may be for the Post Title block to print something like Untitled if the post has no title and the isLink attribute is true.
Great flag! This came up as part of the second FSE call for testing too with @bph saying:
What I did notice was that after I added the Post Tags block, the links wouldn’t work. I would have appreciated a warning or so that a template is missing on the theme, and a link that would bring me to the “How to add a tag page” or something.
I imagine a similar solution is needed for the placeholder as is being discussed for page drafts in the navigation block here: https://github.com/WordPress/gutenberg/issues/29417#issuecomment-790816305
At some point in the future, I would love for "Placholder content" to get a bigger presence, because this issue is not limited just to the post title, but to post content and anything else. It would be nice to have some pre-written placeholder "blog posts" or "pages" that you could populate a template with, in absence of content from the website: beautifully written prose with lovely images and layouts that you can optimize your designs and templates for as you develop. It could add a lot of character to WordPress, while at the same time solving a problem.
The theme author is still able to filer the title as we do in traditional/PHP based themes.
Should this remain up to the theme author, or should it be handled with the block?
/**
* Show '(no title)' in frontend if post has no title.
*/
add_filter(
'the_title',
function( $title ) {
if ( ! is_admin() && empty( $title ) ) {
$title = __( '(no title)', 'textdomain' );
}
return $title;
}
);
Thanks @carolinan
Just checking out your Armando theme and noticed how you filter the_title. Very helpful, thanks again!
I'm closing this one, since we don't render the block if no title exists and @carolinan has provided an example usage of the php filter. Feel free to reopen if there is something more to the issue or something different.