An alternative would be to use WordPress’s build in auto embed, the following line in core is responsible for auto embed:
add_filter( 'the_content', array(&$this, 'autoembed'), 8 );
Which means: Whenever we are about to display content try to auto embed all url’s with a priority of 8.
You could add a custom filter before this one to add the youtube url’s, like so:
add_filter( 'the_content', 'prefix_add_youtube_videos', 7 );
function prefix_add_youtube_videos( $content ) {
$video = get_post_meta( get_the_ID(), 'video_url', true );
if ( ! empty( $video ) ) {
$content .= $video;
}
return $content;
}
So we add our function with priority 7 so it’s before WordPress’s auto embed and so WordPress will embed the video for us. That is less code you’ll have to maintain.
PS Embedding is good! Don’t freeboot!
Related Posts:
- How to get custom post meta using REST API
- What is “meta_input” parameter in wp_insert_post() used for?
- The “_encloseme” Meta-Key Conundrum
- Using get_post_meta with new_to_publish
- So much data in postmeta
- Can I count the number of users matching a value in a multiple value key?
- Auto sort the wp-admin post list by a meta key
- get_post_meta() unserialize issue – returns boolean(false)
- Allow user to create instances of custom field
- Is there a hook / action that is triggered when adding or removing a post thumbnail?
- Get updated meta data after save_post hook
- Save HTML formatted data to post meta using add_post_meta()
- Ordering posts by anniversary using only day and month
- How to break meta values into different items and avoid duplicates?
- ajax delete value from custom field array
- Save attachment custom fields on front end
- How to use pagination with get_post_meta
- Custom fields: In what order are they saved into the DB?
- Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta
- Unable to show ACF’s Image Custom Field properly in Genesis Framework [closed]
- Custom field value based on other custom field values
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- How to display Meta Field Value?
- MySQL query to set wp_postmeta using term_taxonomy_id value
- How to Validate Post Meta type/extension (Video File Image File etc)
- Custom Meta Box not Saving in Posts with Gutenberg Editor
- Combine multiple custom field values into single value
- How do I use wp_query for WordPress search?
- Nav Menu – Add class based on meta keys
- How to query posts with certain custom meta data, and output Post data
- How to wrap meta values seperated by comma in ? [closed]
- Bulk remove post meta
- How to create html block to display extra information on woocommerce single product page
- Can’t get post ID using wp_insert_post_data
- Unique Post Meta Values
- Run a check for multiple meta key values
- WordPress Rest API to call page data associate with custom meta
- Store array as single, serialized post meta field or many post meta fields?
- Hide custom meta data if empty
- How to create a shortcode to print specific values stored in a post meta array?
- Add custom field to all posts in specific post_type
- Button inside Custom Meta Box triggering the Update Button
- How to load an assets based on custom field value?
- get_posts in meta box dropdown not showing latest posts
- Limits, not all post are showen when querying for posts by view count
- Display Custom Meta Box Field Only If Value is Present
- Ordering posts by custom field named “date” in backend
- Stop sending email everytime I updates my post
- Best way to store everyday post views?
- Unable to get specific value from post meta
- Custom meta is not being saved
- IF Custom field value equals ZERO
- How to use media upload on metabox post page without breaking TinyMCE?
- Let’s Create Custom Field Template Documentation
- Branch made by several custom values
- Looping inside block return
- WordPress creates new lines in postmeta table on post update
- change order of images attached to post
- User customising position of WordPress Featured Image
- how can I show name and value of Custom Fields together?
- Can I save post meta programatically without setting metaboxes?
- Insert image into sub-field with update_post_meta
- How to use conditional statement with custom field
- Meta box values are displayed on Custom Fields list. Is it possible to hide them?
- If metabox has content display content
- Best way to achieve multiple links in a post title
- Display Meta Data with HTML?
- How can I add/update post meta in a admin menu page?
- Get author total post votes from post meta
- Group Posts By Custom Meta Value: Date
- custom filed from post in the side bar
- Meta field bulk editing no longer working in WP 6.0 [closed]
- How to display custom fields in hestia theme
- How to speed up post list slowed by update_meta_cache()?
- WordPress Blocks, setAttributes not saving
- Adding Facebook’s image and meta description retrieval capabilities to a WordPress post
- SQL query to change the value of a Custom Field
- Custom meta POST request fired twice when updating a post in Gutenberg
- Add custom field information to source meta data
- Update custom field on page specific to logged in user
- Save, update, get and sanitize post meta as HTML not plain
- Create Meta boxes dynamically
- Saved Post Meta Array Returns as String
- Delete custom meta
- Problem saving meta data
- Check if value exists before saving
- Get meta value when the page is a blog archive
- change attachment custom field onChange event
- wordpress simple post multi rating with post_meta and user_meta
- wp_postmeta are updated for only one page
- Custom fields / meta box output
- Make Custom Fields Public in JSON – API
- Colecting values from custom field checkboxes and displaying them in the post
- Build Array from Input Fields question
- Order by a meta field in query loop
- How can i put a custom field inside this php
- How to add new Metadata options (Date, Author, etc.) for Posts?
- Saving multiple custom meta box fields
- Search for meta_query does not return any result if combined with title
- What is the best way to get a different post’s custom field/postmeta with js?