test text

<div class="video">

        $media = get_media_embedded_in_content( apply_filters( 'the_content', get_the_content() ));



<div class="uitgelichttitel">
    <?php the_title();?>

that's my code

Visual Representation

Finally shows me the video, but I am getting this on the front-end:

Array ( [0] => )


Changing print_r($media) to print($media) removes the video.

Info about the file

This is the entire file. It's called content-video.php. WordPress automatically attached this file to the post format. When it loops through the posts it immediately checks the post format and if it is post format then it fetches the file accordingly. In this case that's content-video.php.

Extra about me

I apologize if this is a no brainer. Have been trying to learn how all of this works for a while now, including plenty of hours today, probably going to be working on figuring this out until the night. Figured maybe I could get someone to tell me what's up in easier terms, there's already a lot that I am trying to get a grasp on. Thank you. I am new to Wordpress theme development, new to PHP and new to JS.

The Goal

Pull the embed video from the post content to display on a different page.

Best Attempt

What I have thus far, which I am still trying to wrap my head around.

The Fix

Provided by TheDeadMedic:

Change "print_r" to "print current"

Loads of gratitude for the help! I finished my registration so that I can contribute to StackExchange in the future.

  • 1
    What are you trying to do that lead you to this? I fixed the code formatting so it shows as a block of code, but it's unclear where this code is located or what the reason you wrote it is for, or what you're trying to do. It looks like an X Y problem, where you've asked how to fix your solution, not how to solve your problem. Also I was a little thrown by the weird nesting formatting of the function call, can you normalise it instead so it's more readable? It's strange that half of it is on one line and the rest is on another but indented
    – Tom J Nowell
    Jun 17, 2022 at 15:04
  • 1
    I have edited the question, hope that clarifies it more. Thank you! @TomJNowell
    – Talha
    Jun 17, 2022 at 15:34

1 Answer 1


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 );
  • This is exactly why I came here, someone that knows a lot more than I do leading me into the right direction. This fixed the issue, despite all that I definitely will address my lack of understanding and continue to learn about PHP by developing more things in the future. I am very glad to be able to continue now instead of being stuck on this issue and having to go through an entire PHP course. Aside from that, sure I learnt how to make a WP theme but I really need to dig into all the files that are included in a WP install. Background functions such as the subject of this post. Thank you <3
    – Talha
    Jun 17, 2022 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.