Skip to content

Instantly share code, notes, and snippets.

@mjangda
Created May 12, 2017 23:21
Show Gist options
  • Select an option

  • Save mjangda/31f49f9c613a664e3f62b3146e85b41d to your computer and use it in GitHub Desktop.

Select an option

Save mjangda/31f49f9c613a664e3f62b3146e85b41d to your computer and use it in GitHub Desktop.

Revisions

  1. mjangda created this gist May 12, 2017.
    13 changes: 13 additions & 0 deletions amphtml-rest-response.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    <?php

    add_filter( 'rest_prepare_post', 'amp_add_amphtml_link_to_rest_response', 10, 2 );

    function amp_add_link_to_rest_response( $response, $post ) {
    if ( ! post_supports_amp( $post ) ) {
    return $response;
    }

    $response->add_link( 'amphtml', amp_get_permalink( $post->ID ) );

    return $response;
    }