-
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);
The ticket ‘Sitemap only shows 1 image with Enfold Theme’ is closed to new replies.