Rank Math is a revolutionary WordPress SEO Plugin that combines the features of many SEO tools and lets you multiply your traffic in the easiest way possible :bulb: :chart_with_upwards_trend: →
When the "Add missing TITLE attributes" or "Add missing ALT attributes" is on and the format is set to "%title%", the value of the attributes for the featured images sometimes holds a wrong value. This happens when the posts are displayed using a custom query and the loop doesn't depend on setup_postdata() to set the global $post to the current post in the custom loop.
To Reproduce
Steps to reproduce the behavior:
Go to Rank Math "General Settings" and open "Images" Tab
Turn the "Add missing TITLE attributes" on and set the format to "%title%"
Create a custom posts query inside another posts archive e.g 'category archive page', may be a loop like this:
Check the title attributes for the displayed featured images, they hold a value different from the displayed post title.
Expected behavior
The automatically generated ALT/TITLE attribute value for the featured image should be the same as the post title being displayed when the format is set to "%title%" from Rank Math image settings.
Suggested code Edit
In this file:
includes/modules/image-seo/class-add-attributes.php
I think the callback used by Rank Math on the filter "post_thumbnail_html" should use a second attribute "$post_id" to get the current displayed post instead of depending on the current global $post.
Describe the bug
When the "Add missing TITLE attributes" or "Add missing ALT attributes" is on and the format is set to "%title%", the value of the attributes for the featured images sometimes holds a wrong value. This happens when the posts are displayed using a custom query and the loop doesn't depend on setup_postdata() to set the global $post to the current post in the custom loop.
To Reproduce Steps to reproduce the behavior:
Expected behavior The automatically generated ALT/TITLE attribute value for the featured image should be the same as the post title being displayed when the format is set to "%title%" from Rank Math image settings.
Suggested code Edit
In this file:
includes/modules/image-seo/class-add-attributes.php
I think the callback used by Rank Math on the filter "post_thumbnail_html" should use a second attribute "$post_id" to get the current displayed post instead of depending on the current global $post.