There may be a more graceful way to do this, but it works:
function shortcode_youtube($atts) {
extract(shortcode_atts(array(
"id" => '',
"align" => 'aligncenter'
), $atts));
global $wp_embed;
$content="http://www.youtube.com/watch?v=" . $id . '';
$embed = $wp_embed->run_shortcode( $content );
return '<div class="'.$align.'">' . $embed . '</div>';
}
add_shortcode("youtube", "shortcode_youtube");
Related Posts:
- Set wmode attribute to transparent for the embed shortcode to make drop-down menu hover over YouTube embed in Internet Explorer
- Why isn’t this youtube shortcode working?
- How to apply an ID to Shortcode Embedded iframe
- Custom youtube shortcode that uses $content
- Adding YouTube button to TinyMCE editor
- How to create a shortcode with 1 parameter (atts)
- shortcodes output before content [duplicate]
- WordPress adds br in between my shortcode
- Shortcodes, HTML tables, and multiple rows
- WP_enqueue_script inside shortcode?
- Shortcode to Gutenberg-block: additional text on front-end and conditional display
- template_redirect to accompany with a shortcode
- How navigation works in custom loop within shortcode?
- Tinymce shortcodes within shortcode contents
- I dont want to show shortcode in tag
- How do I preview the result of a shortcode in the TinyMCE editor?
- WordPress shortcode doesn’t working on HomePage
- Can’t understand $atts in functions?
- Add attribute to shortcode dynamically
- Execute shortcode twice in the same page
- How to parse this shortcode?
- Add custom setting that uses radio button to WP Gallery
- Shortcode with hyphen doesn’t work
- Shortcode parsed incorrectly because of heredoc
- Shortcode “post_per_page” not working
- Shortcode is running in page editor
- Creating shortcode with parameter
- Video Shortcodes not working in WordPress
- Shortcodes won’t work on live environment
- Create shortcode in Child Theme?
- Get post object in shortcode function
- How to insert image and text from admin panel throughout my theme
- Create a short code to display a specific loop
- How to add shortcode to HTML file (not showing on website)
- Custom Shortcode: define cursor position/insertion point?
- How to wp_redirect on ‘init’ hook on condition of current post id?
- Buddypress shortcode for tabs [closed]
- show shortcodes in editor
- Image Shortcode from ACF ID
- Page code showing in WP Dashboard
- echo do_shortcode just prints the shortcode name and not its content
- How to create an incremental list using shortcodes?
- How to Generate html tags using shortcodes?
- Do shortcode that is inserted in a textarea is not displaying properly
- Echo do shortcode with custom field not working
- How to Make Archive ShortCode
- Adding custom form within add_shortcode
- Are Shortcode Attributes Always Passed As Strings?
- wp_editor not rendering the shortcode
- Default WordPress shortcodes not working?
- how to add shortcode in wordpress container [duplicate]
- How to make this shortcode work for post content wordpress [duplicate]
- stop WordPress removing shortcode from content [closed]
- caption shortcode using image alt as caption
- Looking to Customize YouTube Video Embeds
- Is it possible to handle two or more shortcodes in a single page?
- Toggle Shortcode Sanitize Title
- Clearfix Shortcode
- How and when to include shortcode source files
- Use full size images in a specific gallery
- how to create a fav icon shortcode?
- How to deal with WordPress bug: can’t use wrapped and unwrapped shortcode on same post
- Execute Shortcodes when submitting post
- Substituting value via shortcode
- Video shortcode, option are not rendered
- Create shortcode for each form field in contact form 7
- Can’t render shortcode when html tag contains hyphen
- Auto embeds don’t work for attachment descriptions
- Shortcode to appear and show the date not code in Title and description of Social Media sites
- how to add shortcode widget at end of main blog page
- Shortcode result appears above page content
- Shortcode is not showing content when placed in editor (post_type = page)
- How to set up posts per page on WP
- How to insert a short code into Contact Form 7 in WordPress that will call a function once the submit button is pressed
- Unable to make shortcode, what is wrong?
- Multiple shortcodes only use attributes from one of the shortcodes on custom plugin
- Cannot modify class property from shortcode handler function
- How to display a page dependent on a url parameter supplied by a form/button page?
- How do i remove Business feeds Shortcode fatal error
- Can’t place endwhile in the loop properly in a shortcode
- Push Shortcode parameter to template
- latest posts shortcode with image
- Shortcode tags appear on mobile themes
- WordPress Gallery with ID’s Shortcode not Working
- Featured image with link to post shortcode, image displaying above the post
- Video shortcode inside tabs shorcode NOT working
- How to stop unwanted splits in excerpts when using shortcodes for sliders or players
- How to add meta slider lite or other slider to main page header in pinboard theme
- Str_replace using shortcode with multiple changes
- Escaping a shortcode so it displays as-is [duplicate]
- WordPress do_shortcode first iteration
- If do_shortcode is blank, return some message
- Add a short code to a plugin
- Applying if (get_post_meta) to new shortcode
- Add widget/shortcode to sidebar OUTSIDE of the theme
- How to remove https:// from shortcode generated url
- I have the query code but not the shortcode
- wordpress how to sort posts on custom data with plug-in “Search & Filter”
- How to reuse php templates as shortcodes?
- Shortcode attributes from meta query variables