Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Get YouTube video id from url in a custom field

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:

  1. How to get custom post meta using REST API
  2. What is “meta_input” parameter in wp_insert_post() used for?
  3. The “_encloseme” Meta-Key Conundrum
  4. Using get_post_meta with new_to_publish
  5. So much data in postmeta
  6. Can I count the number of users matching a value in a multiple value key?
  7. Auto sort the wp-admin post list by a meta key
  8. get_post_meta() unserialize issue – returns boolean(false)
  9. Allow user to create instances of custom field
  10. Is there a hook / action that is triggered when adding or removing a post thumbnail?
  11. Get updated meta data after save_post hook
  12. Save HTML formatted data to post meta using add_post_meta()
  13. Ordering posts by anniversary using only day and month
  14. How to break meta values into different items and avoid duplicates?
  15. ajax delete value from custom field array
  16. Save attachment custom fields on front end
  17. How to use pagination with get_post_meta
  18. Custom fields: In what order are they saved into the DB?
  19. Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta
  20. Unable to show ACF’s Image Custom Field properly in Genesis Framework [closed]
  21. Custom field value based on other custom field values
  22. Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
  23. How to display Meta Field Value?
  24. MySQL query to set wp_postmeta using term_taxonomy_id value
  25. How to Validate Post Meta type/extension (Video File Image File etc)
  26. Custom Meta Box not Saving in Posts with Gutenberg Editor
  27. Combine multiple custom field values into single value
  28. How do I use wp_query for WordPress search?
  29. Nav Menu – Add class based on meta keys
  30. How to query posts with certain custom meta data, and output Post data
  31. How to wrap meta values seperated by comma in ? [closed]
  32. Bulk remove post meta
  33. How to create html block to display extra information on woocommerce single product page
  34. Can’t get post ID using wp_insert_post_data
  35. Unique Post Meta Values
  36. Run a check for multiple meta key values
  37. WordPress Rest API to call page data associate with custom meta
  38. Store array as single, serialized post meta field or many post meta fields?
  39. Hide custom meta data if empty
  40. How to create a shortcode to print specific values stored in a post meta array?
  41. Add custom field to all posts in specific post_type
  42. Button inside Custom Meta Box triggering the Update Button
  43. How to load an assets based on custom field value?
  44. get_posts in meta box dropdown not showing latest posts
  45. Limits, not all post are showen when querying for posts by view count
  46. Display Custom Meta Box Field Only If Value is Present
  47. Ordering posts by custom field named “date” in backend
  48. Stop sending email everytime I updates my post
  49. Best way to store everyday post views?
  50. Unable to get specific value from post meta
  51. Custom meta is not being saved
  52. IF Custom field value equals ZERO
  53. How to use media upload on metabox post page without breaking TinyMCE?
  54. Let’s Create Custom Field Template Documentation
  55. Branch made by several custom values
  56. Looping inside block return
  57. WordPress creates new lines in postmeta table on post update
  58. change order of images attached to post
  59. User customising position of WordPress Featured Image
  60. how can I show name and value of Custom Fields together?
  61. Can I save post meta programatically without setting metaboxes?
  62. Insert image into sub-field with update_post_meta
  63. How to use conditional statement with custom field
  64. Meta box values are displayed on Custom Fields list. Is it possible to hide them?
  65. If metabox has content display content
  66. Best way to achieve multiple links in a post title
  67. Display Meta Data with HTML?
  68. How can I add/update post meta in a admin menu page?
  69. Get author total post votes from post meta
  70. Group Posts By Custom Meta Value: Date
  71. custom filed from post in the side bar
  72. Meta field bulk editing no longer working in WP 6.0 [closed]
  73. How to display custom fields in hestia theme
  74. How to speed up post list slowed by update_meta_cache()?
  75. WordPress Blocks, setAttributes not saving
  76. Adding Facebook’s image and meta description retrieval capabilities to a WordPress post
  77. SQL query to change the value of a Custom Field
  78. Custom meta POST request fired twice when updating a post in Gutenberg
  79. Add custom field information to source meta data
  80. Update custom field on page specific to logged in user
  81. Save, update, get and sanitize post meta as HTML not plain
  82. Create Meta boxes dynamically
  83. Saved Post Meta Array Returns as String
  84. Delete custom meta
  85. Problem saving meta data
  86. Check if value exists before saving
  87. Get meta value when the page is a blog archive
  88. change attachment custom field onChange event
  89. wordpress simple post multi rating with post_meta and user_meta
  90. wp_postmeta are updated for only one page
  91. Custom fields / meta box output
  92. Make Custom Fields Public in JSON – API
  93. Colecting values from custom field checkboxes and displaying them in the post
  94. Build Array from Input Fields question
  95. Order by a meta field in query loop
  96. How can i put a custom field inside this php
  97. How to add new Metadata options (Date, Author, etc.) for Posts?
  98. Saving multiple custom meta box fields
  99. Search for meta_query does not return any result if combined with title
  100. What is the best way to get a different post’s custom field/postmeta with js?
Categories custom-field Tags custom-field, html5, post-meta, video-player, youtube
How to open port for a specific IP address with firewall-cmd on CentOS? [duplicate]
$_POSTing to and modifying the WP search results page

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress