Images from posts and pages are at “1”

  • Hi, I was setting this up after Yoast and it seems that I have lost my images on a page and post sitemaps.

    Please advice

    • This topic was modified 4 months, 2 weeks ago by Arthur.
Viewing 12 replies - 31 through 42 (of 42 total)
  • Hello, here it is (however, please, consider that our filter works with Uncode since it has its own shortcodes, like uncode_index, and some original attributes like media and medias):

    add_filter('wpseo_sitemap_urlimages', 'uncode_add_images_yoast_sitemap', NULL, 2);
    function uncode_add_images_yoast_sitemap($images, $post_id) {
    
    	$post = get_post($post_id);
    	$content = $post->post_content;
    
    	$image_ids = array();
    
    	//Find uncode_index occurences and match IDs inside them
    	preg_match_all( '/\[uncode_index ([^\]]*)by_id:(.*?)[\||"]/', $content, $uncode_index );
    
    	if ( isset( $uncode_index[2] ) && !empty($uncode_index[2]) ) { //If "by_id" values exist
    		$uncode_index_ids = $uncode_index[2];
    	    foreach ( $uncode_index_ids as $uncode_index_ids_occurence ) {
    	    	$uncode_index_ids_occurence_list = explode(',',$uncode_index_ids_occurence);
    
    	    	foreach ($uncode_index_ids_occurence_list as $uncode_index_id) {
    	            $thumb_id_here = get_post_thumbnail_id($uncode_index_id);//Get featured image IDs from post ID
    	            if ( $thumb_id_here !== ''  && $thumb_id_here != 0 ) {
    		            $image_ids[] = $thumb_id_here; //Store featured image ID
    	            }
    	    	}
    	    }
    	}
    
    	//Find vc_single_image occurences and match IDs inside them
    	preg_match_all( '/\[vc_single_image([^\]]*) media="(.*?)"/', $content, $vc_single_image );
    
    	if ( isset( $vc_single_image[2] ) && !empty($vc_single_image[2]) ) { //If "media" values exist
    		$vc_single_image_ids = $vc_single_image[2];
    	    foreach ( $vc_single_image_ids as $vc_single_image_ids_occurence ) {
                $image_ids[] = $vc_single_image_ids_occurence; //Store single image ID
    	    }
    	}
    
    	//Find vc_gallery occurences and match IDs inside them
    	preg_match_all( '/\[vc_gallery([^\]]*) medias="(.*?)"/', $content, $vc_gallery );
    
    	if ( isset( $vc_gallery[2] ) && !empty($vc_gallery[2]) ) { //If "medias" values exist
    		$vc_gallery_ids = $vc_gallery[2];
    	    foreach ( $vc_gallery_ids as $vc_gallery_ids_occurence ) {
    	    	$vc_gallery_ids_occurence_list = explode(',',$vc_gallery_ids_occurence);
    
    	    	foreach ($vc_gallery_ids_occurence_list as $vc_gallery_id) {
    	            $image_ids[] = $vc_gallery_id; //Store image ID
    	    	}
    	    }
    	}
    
    	$media = get_post_meta($post->ID, '_uncode_featured_media', 1);
    	if ($media !== '') {
    		$image_ids = array_merge($image_ids, explode(',', $media));
    	}
    
    
        foreach ( $image_ids as $image_id ) { //Populate an array with URLs taken from featured image IDs
        	$image_url = wp_get_attachment_image_src($image_id, 'large');
        	$image_title = get_the_title($image_id);
        	$image_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true);
        	$new_data_img = array( 'src' => $image_url[0], 'title' => esc_html($image_title), 'alt' => $image_alt );
        	$images[] = $new_data_img;
        }
    
    	return $images;
    
    }

    Hello Arthur,

    Can you add your site’s FTP access in the Sensitive Data Section so we can add the filter in functions.php file? Updating the code from Theme Editor is failing on your site.

    Looking forward to helping you.

    • This reply was modified 4 months ago by Pratik.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hello,

    I logged into your site and I updated the code in functions.php file. That seemed to have fixed the issue. Can you please confirm?

    Thank you.

    HI Pratik,

    Thank you very much for this. This seems to be working now and I have Rankmath successfully running.

    Will monitor it and report if anything is unstable.

    Also, did you change the child functions.php file or theme functions.php file?

    Thank you very much!

    Arthur

    Hello,

    We always make changes to the theme that is active on your website. You can confirm the same from your end as well.

    If you need help with anything else, please open a new support ticket here so we can help:

    https://support.rankmath.com

    We are always here for assistance.

    Hello, I’m still the Uncode’s developer guy 🙂 Since this ticket seems to be solved, could you provide some details please? If the problem can be solved in Uncode core, we’ll be more than glad to included the solution in the theme itself: another user wrote to us with the same problem and, at the moment, we don’t know what to answer.

    Thank you in advance.

    We have 30+ Uncode sites and we REALLY want to get a solution. Seems there’s still issues with RM recognizing the Alt data inside content blocks and images

    Hello,

    Thank you for contacting Rank Math today.

    I’ll alert the dev team to let you know the solution they worked out on this.

    Please do not hesitate to let us know if you need our assistance with anything else.

    Thank you.

    Hello manuel-undsgn,

    Please add following code in your theme to include the images in the Sitemap:

    
    add_filter('rank_math/sitemap/urlimages', 'uncode_add_images_rank_math_sitemap', NULL, 2);
    function uncode_add_images_rank_math_sitemap($images, $post_id) {
    
    	$post = get_post($post_id);
    	$content = $post->post_content;
    
    	$image_ids = array();
    
    	//Find uncode_index occurences and match IDs inside them
    	preg_match_all( '/\[uncode_index ([^\]]*)by_id:(.*?)[\||"]/', $content, $uncode_index );
    
    	if ( isset( $uncode_index[2] ) && !empty($uncode_index[2]) ) { //If "by_id" values exist
    		$uncode_index_ids = $uncode_index[2];
    			foreach ( $uncode_index_ids as $uncode_index_ids_occurence ) {
    				$uncode_index_ids_occurence_list = explode(',',$uncode_index_ids_occurence);
    
    				foreach ($uncode_index_ids_occurence_list as $uncode_index_id) {
    							$thumb_id_here = get_post_thumbnail_id($uncode_index_id);//Get featured image IDs from post ID
    							if ( $thumb_id_here !== ''  && $thumb_id_here != 0 ) {
    								$image_ids[] = $thumb_id_here; //Store featured image ID
    							}
    				}
    			}
    	}
    
    	//Find vc_single_image occurences and match IDs inside them
    	preg_match_all( '/\[vc_single_image([^\]]*) media="(.*?)"/', $content, $vc_single_image );
    
    	if ( isset( $vc_single_image[2] ) && !empty($vc_single_image[2]) ) { //If "media" values exist
    		$vc_single_image_ids = $vc_single_image[2];
    			foreach ( $vc_single_image_ids as $vc_single_image_ids_occurence ) {
    						$image_ids[] = $vc_single_image_ids_occurence; //Store single image ID
    			}
    	}
    
    	//Find vc_gallery occurences and match IDs inside them
    	preg_match_all( '/\[vc_gallery([^\]]*) medias="(.*?)"/', $content, $vc_gallery );
    
    	if ( isset( $vc_gallery[2] ) && !empty($vc_gallery[2]) ) { //If "medias" values exist
    		$vc_gallery_ids = $vc_gallery[2];
    			foreach ( $vc_gallery_ids as $vc_gallery_ids_occurence ) {
    				$vc_gallery_ids_occurence_list = explode(',',$vc_gallery_ids_occurence);
    
    				foreach ($vc_gallery_ids_occurence_list as $vc_gallery_id) {
    							$image_ids[] = $vc_gallery_id; //Store image ID
    				}
    			}
    	}
    
    	$media = get_post_meta($post->ID, '_uncode_featured_media', 1);
    	if ($media !== '') {
    		$image_ids = array_merge($image_ids, explode(',', $media));
    	}
    
    		foreach ( $image_ids as $image_id ) { //Populate an array with URLs taken from featured image IDs
    			$image_url = wp_get_attachment_image_src($image_id, 'large');
    			$image_title = get_the_title($image_id);
    			$image_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true);
    			$new_data_img = array( 'src' => $image_url[0], 'title' => esc_html($image_title), 'alt' => $image_alt );
    			$images[] = $new_data_img;
    		}
    
    	return $images;
    
    }
    

    I hope that helps.

    HI Pratik, Will this fix allow RM to read the Alt data added to images in Uncode?

    Hi Manuel, is this likely to make it into the next release of Uncode?

    Many thanks, Martin

    Hello,

    Thank you for contacting Rank Math today.

    The code above should allow Rank math to integrate and work efficiently with Unicode. In the issue of whether it will make in the next release of unicode, I’d recommend you get in touch with Unicode support team,

    Hoping this helps you. Thank you.

    ​​​​​​

Viewing 12 replies - 31 through 42 (of 42 total)

You must be logged in to reply to this ticket.