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.