• Resolved Brad Dalton

    (@wordpresssites)


    Images added to a gallery using the gallery shortcode are not indexed. Is there a plugin setting for this?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Maybellyne

    (@maybellyne)

    Hello @wordpresssites,

    Thanks for choosing the Yoast SEO plugin. It analyzes the default WordPress content areas like the title, URL, the main content box (WordPress editor). If you are adding your content through other plugin or theme content boxes (as most page builders do), Yoast SEO may not be able to detect it by default.

    You can also use the filter, wpseo_sitemap_urlimages to register images to appear on the sitemap.

    Thread Starter Brad Dalton

    (@wordpresssites)

    The gallery shortcode is native to WordPress and always has been used in the content area.

    Plugin Support Maybellyne

    (@maybellyne)

    Yoast SEO won’t analyze the shortode. Using the provided filter should help include the images.

    Thread Starter Brad Dalton

    (@wordpresssites)

    Maybellyne. This is the code i used but i cannot see the gallery image URL’s in the sitemap

    function add_gallery_images_to_sitemap( $images, $post_id ) {
    // Get the post content
    $post_content = get_post_field( 'post_content', $post_id );

    // Look for gallery shortcodes
    if ( has_shortcode( $post_content, 'gallery' ) ) {
    // Extract all gallery shortcodes
    preg_match_all( '/\[gallery.*ids=.(.*).\]/', $post_content, $matches );

    if ( isset( $matches[1] ) ) {
    foreach ( $matches[1] as $match ) {
    // Get the image IDs
    $image_ids = explode( ',', $match );

    foreach ( $image_ids as $id ) {
    $image = wp_get_attachment_image_src( $id, 'full' );
    if ( $image ) {
    $images[] = array(
    'src' => $image[0],
    'title' => get_the_title( $id ),
    'alt' => get_post_meta( $id, '_wp_attachment_image_alt', true ),
    );
    }
    }
    }
    }
    }

    return $images;
    }
    add_filter( 'wpseo_sitemap_urlimages', 'add_gallery_images_to_sitemap', 10, 2 );

    “You can also use the filter,?wpseo_sitemap_urlimages?to register images to appear on the sitemap.” I see the image URL’s in the HTML output but not in the sitemap. I’ve missed something? Not using blocks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.