Because print_r
prints a readable version of your variable $media
, which will be an array as per the documentation for get_media_embedded_in_content()
.
You see Array ( [0] => [youtube embed] )
in your browser because it’s rendering the HTML of the array element – if you check the source code of your page you would see something like:
Array (
[0] => <iframe src="..." />
)
But to answer your problem, you should print
(or echo
) with current()
to get the “current” element in an array, which in this case will be the HTML for the first found media element (if one exists):
print current( $media );