Support » Plugin: AMP » get_post_meta in amp?

  • Resolved Jonas


    Hi, I’m trying to implement custom post meta data to display in the single.php AMP template.

    I’m however unable to show the data from the wordpress function get_post_meta($post->ID, ‘post-meta’, true) – how do you implement that in AMP?

    Here’s a test for a youtube video:

    The post meta data is filled out with: O7OqaMkymWI

    My code is

    <script async custom-element="amp-youtube" src=""></script>
    <?php $src = get_post_meta($post->ID, 'meta-data', true);
    echo '<amp-youtube layout="responsive" data-videoid="'. $src.'" width="480" height="270" allowfullscreen></amp-youtube>';

    Intented result:

    <amp-youtube layout="responsive" data-videoid="O7OqaMkymWI" width="480" height="270" allowfullscreen></amp-youtube>

    The error is

    Uncaught (in promise) Error: failed to build: amp-youtube#3: Exactly one of data-videoid or data-live-channelid should be present for <amp-youtube> amp-youtube

    Thanks for the help!

    • This topic was modified 1 year, 6 months ago by  Jonas.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi, Jonas!

    Your report was very detailed.

    Running your code in the amp-validator, it seems that a possible cause could be that the value in data-videoid may not be valid (empty)

    What’s the value of $src in your code?

    That may be the cause.

    Also, allowfullscreen may not work in AMP, as it is not allowed in amp-youtube elements.

    Best regards.



    Hi Oscar, thanks for your response.

    I was using $post->ID instead of get_the_id() for get_post_meta. So the $src should have been $src = get_post_meta(get_the_id(), 'meta-data', true);

    I didn’t notice calling $post->ID inside a loop would be funky making the post meta not showing up. All resolved!

    • This reply was modified 1 year, 6 months ago by  Jonas.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_post_meta in amp?’ is closed to new replies.