I’m writing the below pieces of code in “Text” mode of the posts editor.
Does work:
http://www.youtube.com/watch?v=xxxxxxxxxxx
Does work:
<p>test
http://www.youtube.com/watch?v=xxxxxxxxxxx
test</p>
Doesn’t work:
<p>http://www.youtube.com/watch?v=xxxxxxxxxxx</p>
The last link isn’t converted to the YouTube video. I’m wondering if anyone noticed that too and if there’s any known fix to that?
The reason why this is happening, seems to be found in the file
wp-includes/class-wp-embed.php
in theautoembed
call-back method:where
As I understand it, the matching lines have to contain only a link, which could be wrapped by any number of whitespace characters before and after the link itself.
So this pattern would exclude this line:
You could try to add your own
the_content
filter that adds a new line before and after your links inside the paragraph tags around your link. This should be done before theautoembed
filter is executed, so it should have priority under8
.Filter Example:
One can play with the regular expressions in this great online tool:
http://regexr.com?36eat
where I’ve inserted the pattern:
with the replacement:
You can adjust this to your needs.
Here is one idea for such a custom filter: