Sitemap only shows 1 image with Enfold Theme

#40299
  • Resolved Giuseppe Mazzardi
    Rank Math free

    Hi,

    I use Enfold Theme,
    when I create the sitemap, RankMath only displays the posts or pages as if they only contained 1 image, I have pages with over 10 images, but the sitemap only shows 1.

    I have always used Yoast. With yoast the images in the sitemap were greater than 1 (but not all those present on the pages). By adding this string in the function.php file (which I attach below) the problem with Yoast is solved.

    But with RankMath instead I don’t know how to modify the file to see all the images.

    Here is the code for Enfold using Yoast:

    //add image to site maps
    function avia_extract_shortcode($elements, $content) {
    $container = array();
    if(!empty($elements)) {
    foreach ($elements as $key => $element)
    {
    preg_match_all($element[ā€˜patternā€™], $content, $shortcodes);
    foreach($shortcodes[0] as $shortcode)
    {
    switch ($element[ā€˜sourceā€™]) {
    case ā€˜idsā€™:
    $src = ā€˜/ids=\\\'(\d+(,\d+)*)\\\ā€™/ā€™;
    break;
    case ā€˜srcā€™:
    $src = ā€˜/attachment=\\\'(\d+)\\\ā€™/ā€™;
    break;
    case ā€˜sidā€™:
    $src = ā€˜/id=\\\'(\d+)\\\ā€™/simā€™;
    break;
    default:
    return;
    }
    
    $sid = array();
    
    preg_match_all($src, $shortcode, $id);
    
    if($src = ā€˜sidā€™) {
    foreach($id[1] as $key => $value) {
    $sid[] = $value;
    }
    
    $sid = implode(ā€˜,ā€™, $sid);
    $id[1] = $sid;
    }
    
    $container[] = $id[1];
    }
    }
    }
    
    if(!empty($container)) {
    foreach($container as $key => $value) {
    $container[$key] = explode(ā€˜,ā€™, $value);
    }
    }
    
    if (count($container) > 0) {
    $container = call_user_func_array(ā€˜array_mergeā€™, $container);
    }
    
    return $container;
    }
    
    function avia_filter_wpseo_sitemap_urlimages($images, $post_id)
    {
    $post = get_post($post_id);
    if (is_object($post)) {
    $content = $post->post_content;
    $elements = apply_filters(ā€˜avf_add_elements_wpseo_sitemapā€™,
    array(
    ā€˜masonryā€™ => array(
    ā€˜patternā€™ => ā€˜/\[av_masonry_gallery [^]]*]/ā€™,
    ā€˜sourceā€™ => ā€˜idsā€™
    ),
    ā€˜galleryā€™ => array(
    ā€˜patternā€™ => ā€˜/\[av_gallery [^]]*]/ā€™,
    ā€˜sourceā€™ => ā€˜idsā€™
    ),
    ā€˜horizontalā€™ => array(
    ā€˜patternā€™ => ā€˜/\[av_horizontal_gallery [^]]*]/ā€™,
    ā€˜sourceā€™ => ā€˜idsā€™
    )
    ), $elements, $post_id);
    
    $ids = avia_extract_shortcode($elements, $content);
    
    foreach ($ids as $id)
    {
    $title = get_the_title($id);
    $alt = get_post_meta($id, ā€˜_wp_attachment_image_altā€™, true);
    $src = wp_get_attachment_url($id);
    $images[] = array(ā€˜srcā€™ => $src, ā€˜titleā€™ => $title, ā€˜altā€™ => $alt);
    }
    }
    
    return $images;
    }
    add_filter(ā€˜wpseo_sitemap_urlimagesā€™, ā€˜avia_filter_wpseo_sitemap_urlimagesā€™, 10, 2);
    add_filter(ā€˜avf_add_elements_wpseo_sitemapā€™, function($elements, $postid) {
    $image = array(
    ā€˜imageā€™ => array(
    ā€˜patternā€™ => ā€˜/\[av_image [^]]*]/ā€™,
    ā€˜sourceā€™ => ā€˜srcā€™
    ),
    ā€˜accordionā€™ => array(
    ā€˜patternā€™ => ā€˜/\[av_slideshow_accordion(.+?)?\](?:(.+?)?\[\/av_slideshow_accordion\])?/simā€™,
    ā€˜sourceā€™ => ā€˜sidā€™
    ),
    ā€˜slideshowā€™ => array(
    ā€˜patternā€™ => ā€˜/\[av_slideshow(.+?)?\](?:(.+?)?\[\/av_slideshow\])?/simā€™,
    ā€˜sourceā€™ => ā€˜sidā€™
    ),
    ā€˜slideshow_fullā€™ => array(
    ā€˜patternā€™ => ā€˜/\[av_slideshow_full(.+?)?\](?:(.+?)?\[\/av_slideshow_full\])?/simā€™,
    ā€˜sourceā€™ => ā€˜sidā€™
    ),
    ā€˜slideshow_fullscreenā€™ => array(
    ā€˜patternā€™ => ā€˜/\[av_fullscreen(.+?)?\](?:(.+?)?\[\/av_fullscreen\])?/simā€™,
    ā€˜sourceā€™ => ā€˜sidā€™
    )
    );
    
    return array_merge($image, $elements);
    }, 10, 2);
Viewing 2 replies - 16 through 17 (of 17 total)
Viewing 2 replies - 16 through 17 (of 17 total)

The ticket ‘Sitemap only shows 1 image with Enfold Theme’ is closed to new replies.