YouTube link display issues and fix

  • Unknown's avatar

    I noticed that if I had a YouTube link on the first or last line of the post content, then it would just display the URL text instead of showing the YouTube player. If the YouTube link was anywhere else in the content, then the embedded player displayed correctly.

    I tracked down the problem to the add_filter(‘the_content’, ‘add_custom_content’) line of code in functions.php in my child theme. If I disabled the filter, then the YouTube embedded video player would always display correctly. It seems that modifying $content causes a problem with YouTube links on the first or last line.

    I did a little research, and it looks like “oEmbed” is using for displaying the YouTube player, so the problem may not be with WordPress itself.

    I found a fix is to put all YouTube in the [embed][/embed] tags, which will make the video player display regardless of location in the other content. The other option is to just not put YouTube links on the first or last line, if you are modifying the content with a filter.

    Just thought I would share in case anyone else is having this same issue.

    The blog I need help with is: (visible only to logged in users)

  • Hi there,

    Thanks for sharing, though what you describe only applies to the open source WordPress software found on WordPress.org.

    WordPress.com does not support the embed shortcode, but instead we have our own Youtube shortcode for embedding Youtube videos:

    https://en.support.wordpress.com/videos/youtube/

    It could be that the oEmbed implementation for Youtube in the open source version of WordPress needs to be updated, so perhaps you should raise this in the WordPress.org forums at https://wordpress.org/support/ so the community who works on that software can take a look.

  • The topic ‘YouTube link display issues and fix’ is closed to new replies.