Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostTitle: Empty heading tag rendered for posts without titles #69039

Open
3 of 6 tasks
SainathPoojary opened this issue Feb 5, 2025 · 6 comments · May be fixed by #69040
Open
3 of 6 tasks

PostTitle: Empty heading tag rendered for posts without titles #69039

SainathPoojary opened this issue Feb 5, 2025 · 6 comments · May be fixed by #69040
Assignees
Labels
[Block] Post Title Affects the Post Title Block [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@SainathPoojary
Copy link
Contributor

SainathPoojary commented Feb 5, 2025

Description

The Query Loop Block's Post Title component renders an empty <h2> tag for posts without titles, unlike other blocks like Latest Posts which show "(no title)". Additionally, when "Make title a link" is enabled, unexpected spacing appears around the heading tag. This creates inconsistency with WordPress core behavior and affects the layout.

Step-by-step reproduction instructions

  1. Create a new post
  2. Add a Query Loop Block
  3. Select Post Title in the pattern or add it separately
  4. Make sure your query includes at least one post without a title
  5. Observe the editor - empty <h2> tag is rendered for posts without titles
  6. Enable "Make title a link" in block settings
  7. Notice unexpected spacing appears around the heading tag
  8. Compare with Latest Posts block where "(no title)" is displayed

Screenshots, screen recording, code snippet

2025-02-05.12-44-15.mp4

Environment info

  • WordPress: 6.8-alpha-59711
  • PHP: 8.2.27
  • Server: Apache/2.4.62 (Debian)
  • Database: mysqli (Server: 11.4.4-MariaDB-ubu2404 / Client: mysqlnd 8.2.27)
  • Browser: Chrome 132.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.0
  • MU Plugins: None activated
  • Plugins: Gutenberg 20.2.0-rc.1

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure
@SainathPoojary SainathPoojary added the [Type] Bug An existing feature does not function as intended label Feb 5, 2025
@SainathPoojary SainathPoojary linked a pull request Feb 5, 2025 that will close this issue
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Feb 5, 2025
@Mamaduka Mamaduka added the [Block] Post Title Affects the Post Title Block label Feb 5, 2025
@Mamaduka
Copy link
Member

Mamaduka commented Feb 5, 2025

These seem to be edge cases. It would be rare for WP installations to have published posts without titles. The Latest Posts widget block is old; I don't think it should be used to derive best practices.

The Post Title block can also be used outside of the Query block, in templates like Single post/page. The block here should reflect the actual state of the post-title property. Having a fallback changes that.

cc @afercia, @carolinan

@carolinan
Copy link
Contributor

Posts maybe: does the same thing happen for other post types?

@afercia
Copy link
Contributor

afercia commented Feb 5, 2025

Although they seem edge cases, for no reason WordPress should ever render empty headings on the front end. There is also the risk it renders empty links, which is even worse.

@carolinan
Copy link
Contributor

Related: #59996

@Mamaduka
Copy link
Member

Mamaduka commented Feb 5, 2025

The block renders nothing when the title is empty on the front end. I think the issue is more about rendering empty values when the block is used in the Query loop.

$title = get_the_title();
if ( ! $title ) {
return '';
}

@afercia
Copy link
Contributor

afercia commented Feb 5, 2025

Oh ok thanks. The fact the 'empty' block behavior is not standardized across blocks is really confusing though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Title Affects the Post Title Block [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants