Hello,
Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.
Our content analysis API is not yet compatible with all page builders but this is something that is on our to do list.
At the moment, you can seek the help of your developer to loop through all the indexable images added by the builder and add them to the sitemap by using the following filter:
/**
* Filter images to be included for the post in XML sitemap.
*
* @param array $images Array of image items.
* @param int $post_id ID of the post.
*/
add_filter( 'rank_math/sitemap/urlimages', function( $images, $post_id ){
return $images;
}, 10, 2);
Looking forward to helping you. Thank you.
Hi Michael,
Could you give an example of how to apply this filter, where do i add the code?
thnx for your quick reply!
Hi Gaetan,
Thanks for the follow up.
This code should be added to your theme’s/child-theme’s functions.php.
Here is an example of getting images added through the WPBakery page builder:
add_filter( 'rank_math/sitemap/urlimages', function( $images, $id ){
if ( empty( $images ) ) {
$post = get_post( $id );
if ( $post && strpos( $post->post_content, '[vc_row' ) !== false ) {
preg_match_all( '/(?:image|images|ids|include)\=\"([^\"]+)\"/', $post->post_content, $matches );
foreach ( $matches[1] as $m ) {
$ids = explode( ',', $m );
foreach ( $ids as $id ) {
if ( (int) $id ) {
$images[] = array(
'src' => wp_get_attachment_url( $id ),
'title' => get_the_title( $id ),
);
}
}
}
}
}
return $images;
}, 10, 2 );
I hope this info helps. Thank you.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.