• Resolved fireflier10

    (@fireflier10)


    I have added this code to my child functions.php in an effort to get my images to index correctly with the CDN setup:

    /* YOAST CDN SETUP */
    
    add_filter( 'wpcf7_support_html5_fallback', '__return_true' );
    
    function wpseo_cdn_filter( $uri ) {
    return str_replace( 'https://markartall.com', 'https://cdn.markartall.com', $uri );
    }
    add_filter( 'wpseo_xml_sitemap_img_src', 'wpseo_cdn_filter' );

    It seems to be working on my post sitemap but not my page sitemap.

    Any idea why this would happen?

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Sa?a

    (@stodorovic)

    If pages are created by some page builder then it’s possible that filter wpseo_xml_sitemap_img_src can’t work. I think that you could try filter wpseo_sitemap_urlimages with higher priority.

    Thread Starter fireflier10

    (@fireflier10)

    Thank you for the input! I tried swapping the code, but I am still having the issue.

    It’s strange because we have other installs set up similarly with the same code, lugins, and theme, and they work as expected. I did try troubleshooting by turning off the active theme (Avada) to see if it was causing the problem; however, even when I turned it off and used the basic 2019 theme I still had the same issue.

    We’re also hosting on WPEngine so I reached out to them, but they couldn’t find the issue. We do also use Cloudflare as well as wp rocket and imagify. I thought imagify could possibly be the issue, but we have it turned on for our other site with the same code and it works.

    Sa?a

    (@stodorovic)

    If page is created by fusion builder (it’s separate plugin) then method parse_html_images can’t find all images. Fusion builder uses filter wpseo_sitemap_urlimages to “extract images” from their shortcodes (see fusion-builder/inc/lib/inc/class-fusion-images.php – method extract_img_src_for_yoast).

    Arguments for these filters (wpseo_xml_sitemap_img_src and wpseo_sitemap_urlimages) are different. So, you need to create new PHP code, not only replace filter name (and you need to add higher priority for the filter).

    I could create PHP snippet, but I can’t do it before next week.

    Sa?a

    (@stodorovic)

    I’ve created PHP snippet which will run after fusion builder parsing.

    /**
     * Change image src attributes after parsing all images.
     */ 
    add_filter( 'wpseo_sitemap_urlimages', function( $urlimages ) {
    	foreach( $urlimages as $url_key => $url ) {
    		if ( ! empty( $url['src'] ) && is_string( $url['src'] ) ) {
    			$urlimages[ $url_key ]['src'] = preg_replace( '#^https://markartall.com#', 'https://cdn.markartall.com', $url['src'], 1 );
    		}
    	}
    
    	return $urlimages;
    }, 20 );
    

    I prefer preg_replace instead of str_replace because previous code will replace only begin of an URL.

    Thread Starter fireflier10

    (@fireflier10)

    That works! Thank you so much for your help! Sorry for the misunderstanding. Php is not a language I’m very familiar with.

    I really appreciate it.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Page Sitemap Image URLS not showing CDN URL After Adding Recommended Code’ is closed to new replies.