Background of my Problem: I have several hundred images with urls stored in a Toolset Types custom wordpress embedded field, along with video urls. I can display my videos no problem from the embedded field but the images only show the URL not the image.
Solution approach: I'm trying to write a function to register an embed handler for self hosted images: where the URL refers to my own site, and the function will spit out the markup I need, in this case an image tag.
Here is a sample URL for one of my images: https://mysite.ca/mydirectorypath/sampleimage.jpg
I've looked here https://wordpress.stackexchange.com/search?q=wp_embed_register_handler
but I don't see an example for images plus I don't understand regex. I was hoping someone could help me modify a function like this below from https://codex.wordpress.org/Function_Reference/wp_embed_register_handler to fit my self hosted image scenario:
<?php
wp_embed_register_handler( 'forbes', '#http://(?:www|video)\.forbes\.com/(?:video/embed/embed\.html|embedvideo/)\?show=([\d]+)&format=frame&height=([\d]+)&width=([\d]+)&video=(.+?)($|&)#i', 'wp_embed_handler_forbes' );
function wp_embed_handler_forbes( $matches, $attr, $url, $rawattr ) {
$embed = sprintf(
'<iframe src="http://www.forbes.com/video/embed/embed.html?show=%1$s&format=frame&height=%2$s&width=%3$s&video=%4$s&mode=render" width="%3$spx" height="%2$spx" frameborder="0" scrolling="no" marginwidth="0" marginheight="0"></iframe>',
esc_attr($matches[1]),
esc_attr($matches[2]),
esc_attr($matches[3]),
esc_attr($matches[4])
);
return apply_filters( 'embed_forbes', $embed, $matches, $attr, $url, $rawattr );
}
?>
many thanks
get_post_meta
then put them intoimg
andiframe
tags? Note that regular expressions aren't a WP thing, you could take matching that URL and eliminate the WordPress component entirely and ask about that part on stack overflow, and get a lot more eyes on it, otherwise anybody answering has to know both WordPress and regular expressions