Advertisement
EduardET

Untitled

May 23rd, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.61 KB | None | 0 0
  1. function dm_filter_wpseo_sitemap_urlimages($images, $post_id) {
  2.     $post = get_post($post_id);
  3.  
  4.     if (is_object($post)) {
  5.         $content = $post->post_content;
  6.  
  7.         # Parse Divi Image modules
  8.         preg_match_all('/\[et_pb_image [^]]*]/', $content, $divi_im_images);
  9.  
  10.         foreach ($divi_im_images[0] as $divi_im_image) {
  11.         # Add the image to the sitemap
  12.             preg_match('/src="([^"]*)"/', $divi_im_image, $src);
  13.             preg_match('/title_text="([^"]*)"/', $divi_im_image, $title);
  14.             preg_match('/alt="([^"]*)"/', $divi_im_image, $alt);
  15.             $images[] = array('src' => $src[1], 'title' => $title[1], 'alt' => $alt[1]);
  16.         }
  17.  
  18.         # Parse Divi Blurb modules
  19.         preg_match_all('/\[et_pb_blurb [^]]*]/', $content, $divi_bm_images);
  20.         foreach ($divi_bm_images[0] as $divi_bm_image) {
  21.             if (preg_match('/image="([^"]*)"/', $divi_bm_image, $image)) {
  22.             # If the blurb has an image, add it to the sitemap
  23.                 preg_match('/title="([^"]*)"/', $divi_bm_image, $title);
  24.                 preg_match('/alt="([^"]*)"/', $divi_bm_image, $alt);
  25.                 $images[] = array('src' => $image[1], 'title' => $title[1], 'alt' => $alt[1]);
  26.             }
  27.         }
  28.  
  29.         # Parse Divi Image Gallery modules
  30.         preg_match_all('/\[et_pb_gallery [^]]*]/', $content, $divi_igm_images);
  31.  
  32.         foreach ($divi_igm_images[0] as $divi_im_image) {
  33.         # Add the image to the sitemap
  34.             preg_match('/src="([^"]*)"/', $divi_im_image, $src);
  35.             preg_match('/title_text="([^"]*)"/', $divi_im_image, $title);
  36.             preg_match('/alt="([^"]*)"/', $divi_im_image, $alt);
  37.             $images[] = array('src' => $src[1], 'title' => $title[1], 'alt' => $alt[1]);
  38.         }
  39.     }
  40.  
  41.     return $images;
  42. }
  43. add_filter('wpseo_sitemap_urlimages', 'dm_filter_wpseo_sitemap_urlimages', 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement