Possible to add youtube title into WordPress [embed][/embed]?

I am trying to figure out if it is possible for the shortcode feature on WordPress to display a title within the iframe?

When inspecting the youtube video once it is being displayed on the page, it appears like:

Read More
<iframe width="940" height="529" src="https://www.youtube.com/embed/xLZvgt_bPwE?feature=oembed" frameborder="0" allowfullscreen=""></iframe>

Would there be a way to edit the embed feature to also include a title (ex: <iframe width="940" height="529" title="Youtube Video" src="https://www.youtube.com/embed/xLZvgt_bPwE?feature=oembed" frameborder="0" allowfullscreen=""></iframe> once it is displayed on the page or post?

Related posts

1 comment

  1. If you add this filter and function to your functions.php it should provide your desired result 🙂

    function add_iframe_title($iframe){
        if($iframe)
        {
            $attributes = 'title="Embedded Video"';
            $iframe = str_replace('></iframe>', ' ' . $attributes . '></iframe>', $iframe);
    
            return $iframe;
        }
    
        return false;
    }
    
    add_filter('embed_oembed_html', 'my_embed_oembed_html', 99, 4);
    function my_embed_oembed_html($html, $url, $attr, $post_id) {
      if($html)
      {
        return add_iframe_title($html);
      }
      return false;
    }
    

Comments are closed.