-
-
Save chriswiggins/0756f61f745b9b08cc13e86573768f05 to your computer and use it in GitHub Desktop.
<?php | |
/* Add impreza images to Yoast sitemap, since Yoast doesn't read impreza's Page | |
* Builder code - borrowed from (https://github.com/Yoast/wordpress-seo/issues/4808) */ | |
function impreza_filter_wpseo_sitemap_urlimages($images, $post_id) | |
{ | |
$post = get_post($post_id); | |
if (is_object($post)) { | |
$content = $post->post_content; | |
# Parse impreza Image modules | |
preg_match_all("/image=\"(\d+)\"/", $content, $impreza_images); | |
if(count($impreza_images) < 2){ | |
return $images; | |
} | |
foreach ($impreza_images[1] as $impreza_image_id) | |
{ | |
$attachment = wp_prepare_attachment_for_js( $impreza_image_id ); | |
$images[] = array( | |
'src' => $attachment["url"], | |
'title' => $attachment["title"], | |
'alt' => $attachment["description"] | |
); | |
} | |
} | |
return $images; | |
} | |
add_filter('wpseo_sitemap_urlimages', 'impreza_filter_wpseo_sitemap_urlimages', 10, 2); | |
?> |
-1 Add better error handling.
@xZeroMCPE you're welcome to update it yourself if you think it's so terrible
yoast sitemap generation and wpbakery broke again resulting in thin pages and seo penalty.
I'm trying to implement this snippet to manually add images for specific posts/pages/portfolios that contain images within wpbakery pagebuilder blocks.
Can you let me know how and where to put your snippet function to make it work? Do I have to create a function snippet like the above for each and every page/post/portfolio I'd like to manually inject into the sitemap, or can I just put every image and post in this function?
Where in this function do I have to put the page/post/image id to make it work?
Do I just replace url in "url" with my url?
'src' => $attachment["url"],
'title' => $attachment["title"],
'alt' => $attachment["description"]
Or does this function work with ALL images on every post/page/portfolio out of the box?
Sorry for my ignorance.
-1 Add better error handling.