Title: Auto-embed not working
Last modified: August 30, 2016

---

# Auto-embed not working

 *  [Syhlver](https://wordpress.org/support/users/syhlver/)
 * (@syhlver)
 * [11 years ago](https://wordpress.org/support/topic/auto-embed-not-working-1/)
 * Hi,
 * When I insert a youtube link into the editor, the video is not embed.
    I see 
   that WordPress need a valid post ID for embedding a youtube link in the tinymce
   editor. (And the widget can’t provide that.)
 * I’m on a new install of WordPress ( 4.2.2 with Twenty Fifteen) and Black Studio
   TinyMCE Widget in the last version which is the only plugin enabled.
 * So it doesn’t work on the widgets.php and also on the customize.php admin page.
 * Thanks for your help !
 * [https://wordpress.org/plugins/black-studio-tinymce-widget/](https://wordpress.org/plugins/black-studio-tinymce-widget/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [Marco Chiesi](https://wordpress.org/support/users/marcochiesi/)
 * (@marcochiesi)
 * [11 years ago](https://wordpress.org/support/topic/auto-embed-not-working-1/#post-6236633)
 * Unfortunately this depend on a WordPress limitation, which needs a post ID for
   parsing embedded codes. See [this topic](https://core.trac.wordpress.org/ticket/30835)
   for further info.
    Anyway the embed do render fine on the frontend. It’s just
   the preview that doesn’t work.
 *  Thread Starter [Syhlver](https://wordpress.org/support/users/syhlver/)
 * (@syhlver)
 * [11 years ago](https://wordpress.org/support/topic/auto-embed-not-working-1/#post-6236701)
 * Okay, thanks for your answer, I will see if I can do something to avoid this 
   limitation.
    I’ll tell you if I found something !
 *  Thread Starter [Syhlver](https://wordpress.org/support/users/syhlver/)
 * (@syhlver)
 * [11 years ago](https://wordpress.org/support/topic/auto-embed-not-working-1/#post-6236708)
 * So, I have a solution.
    It’s a workaround, but it respond to my needs.
 * For embeding a link, WordPress need a post ID of an existing post.
    So my solution
   is to create a custom post type (not public, not queryable, etc..). Then, I create
   a single post for this custom post type (in the code) and I register the given
   ID in an option. And finally in each widget form content, I put a hidden input
   named « post_ID » containing the previously created post ID as value.
 * # —————————————————————-
    # Create a private custom post type # This CPT will
   only contain a single post. This will be used for links embed preview in widget
   tinymce editor
 * function fCreateHiddenCPT()
    {
 *  # ———————————————————–
    # Register the post type
 *  $args = array(
    ‘public’ => false, ‘publicly_queryable’ => false, ‘show_ui’ 
   => false, ‘query_var’ => false, ‘rewrite’ => false, ‘capability_type’ => ‘post’,‘
   hierarchical’ => false, ‘menu_position’ => null, ‘show_in_nav_menus’ => false,‘
   has_archive’ => false );
 *  register_post_type(‘hiddencpt’,$args);
 * }
 * # ———————————————————–
    # Create the single post
 * function fCreateSingleHiddenCPT()
    { $queryPost = new WP_Query(‘post_type=hiddencpt’);
   $totalPost = $queryPost->post_count;
 *  if($totalPost == 0)
    { $argPost = array(‘post_type’ => ‘hiddencpt’); $idPreviewWidgetPost
   = wp_insert_post($argPost);
 *  // Add the id of the post reference in an option
    update_option(‘idPreviewWidgetPost’,
   $idPreviewWidgetPost); } }
 * # ———————————————————–
    # For make it working in customize.php
 * function fAddIdPreviewWidgetPost()
    { echo ‘<input type=”hidden” id=”post_ID”
   name=”post_ID” value=”‘.get_option(‘idPreviewWidgetPost’).'”>’; }
 * add_action(‘customize_register’, array( $this, ‘fAddIdPreviewWidgetPost’) );
 *  Thread Starter [Syhlver](https://wordpress.org/support/users/syhlver/)
 * (@syhlver)
 * [11 years ago](https://wordpress.org/support/topic/auto-embed-not-working-1/#post-6236717)
 * And for the function fAddIdPreviewWidgetPost, it’s better to use it in those 
   hooks (better than show it in each widget) :
 * add_action( ‘widgets_admin_page’, array( $this, ‘fAddIdPreviewWidgetPost’ ) );
   
   add_action( ‘customize_controls_init’, array( $this, ‘fAddIdPreviewWidgetPost’));
 *  Plugin Author [Marco Chiesi](https://wordpress.org/support/users/marcochiesi/)
 * (@marcochiesi)
 * [10 years, 12 months ago](https://wordpress.org/support/topic/auto-embed-not-working-1/#post-6236766)
 * Thank you for sharing your workaround. I think I’ll add it in one of the next
   releases.
 *  Plugin Author [Marco Chiesi](https://wordpress.org/support/users/marcochiesi/)
 * (@marcochiesi)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/auto-embed-not-working-1/#post-6236832)
 * Hi Syhlver,
    we finally implemented your idea, even if in a different way (in
   the meantime WordPress implementation changed). This feature is actually included
   in our dev version (available on [GitHub](https://github.com/black-studio/black-studio-tinymce-widget)),
   and it will be available in future releases. Thank you again for your suggestion.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Auto-embed not working’ is closed to new replies.

 * ![](https://ps.w.org/black-studio-tinymce-widget/assets/icon.svg?rev=2627604)
 * [Black Studio TinyMCE Widget](https://wordpress.org/plugins/black-studio-tinymce-widget/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/black-studio-tinymce-widget/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/black-studio-tinymce-widget/)
 * [Active Topics](https://wordpress.org/support/plugin/black-studio-tinymce-widget/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/black-studio-tinymce-widget/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/black-studio-tinymce-widget/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [Marco Chiesi](https://wordpress.org/support/users/marcochiesi/)
 * Last activity: [10 years, 8 months ago](https://wordpress.org/support/topic/auto-embed-not-working-1/#post-6236832)
 * Status: not resolved