Skip to content

Avoid duplicate get_the_title() calls in render_block_core_post_featured_image() #70812

@mukeshpanchal27

Description

@mukeshpanchal27

Description

While working on Accurate sizes: Add support for core/post-featured-image block, I noticed that the render_block_core_post_featured_image() function calls get_the_title( $post_ID ) twice when generating the alt attribute for the featured image.

This can be slightly optimized for performance and clarity by storing the post title in a local variable before using it. This avoids redundant function calls and improves readability.

Step-by-step reproduction instructions

  1. Create a post with a title and featured image.
  2. Use a Post Featured Image block in a page or post.
  3. View the rendered markup and confirm the alt attribute reflects the post title.
  4. Remove the title and confirm that the fallback logic still applies correctly.

Screenshots, screen recording, code snippet

No response

Environment info

No response

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

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions