I have this structure for my content.php :
<div class="featured"> <!--featured image here--> </div> <h1 class="entry-title">Post Title</h1> <div class="entry-content"> <?php the_content(); ?> </div>
I would like to move the first oEmbed in
the_content() to the area enclosed by
.featured such that the title will appear after the media content. I have come across these few methods :
autoembed as mentioned here, so I'll need to create a new custom field to enter the URL for oembed and run through the code below :
// add filters for oEmbed global $wp_embed; add_filter( 'my_media_filter', array( $wp_embed, 'autoembed' ), 8 ); // add filter for oEmbed $media = apply_filters( "my_media_filter", $media ); // print embedded media echo $media;
However, using this method would mean that if I switch my theme, I won't be able to see these media content unless I modify it to retrieve the URL from the custom field and run through these codes. Besides, the oembed won't be cached using this method although it would be if it's in
wp_oembed_get as mentioned in the codex. It's also done using a new custom field for the media URL. Again, I think this does not provide caching and I've been getting gzinflate(): data error when I used this method. Here's the error code :
WARNING: C:\xampp\htdocs\wordpress\wp-includes\class-http.php:2108 - gzinflate(): data error require('C:\xampp\htdocs\wordpress\wp-blog-header.php'), require_once('C:\xampp\htdocs\wordpress\wp-includes\template-loader.php'), include('C:\xampp\htdocs\wordpress\wp-content\themes\theme1\archive.php'), get_template_part, locate_template, load_template, require('C:\xampp\htdocs\wordpress\wp-content\themes\theme1\content-video.php'), wp_oembed_get, WP_oEmbed->get_html, WP_oEmbed->fetch, WP_oEmbed->_fetch_with_format, wp_safe_remote_get, WP_Http->get, WP_Http->request, WP_Http->_dispatch_request, WP_Http_Curl->request, WP_Http_Encoding::decompress, gzinflate
apply_filters('the_content', $content) as shown here.
However, I'm getting the same error message as using the method above, and I'm not sure whether this will provide caching? *Edit : Now for some unknown reasons I'm not getting the error message in method #2 when I use this method. Edit : The error message above would be generated for the first time loading the oembed content before the cache is generated in the database because it wasn't loaded in the Post Editor (which explains why it would happen all the time for method #2 as no cache will be generated in that case). Is there any way I can let it cache after applying
So, method #3 seems to work the best as it can also work with WP's shortcodes to include poster image or alternative file format for self-uploaded videos, but it will produce the error message unless it has been loaded at least once to generate the cache into wp_postmeta. Is there any way to solve this last remaining problem?
Thanks for helping!