Tuesday, 28 August 2018

change links on amp to link to amp

We would like to link amp to amp if the linked page has an amp version. We have amp structured like that: test.de/test/amp

Unfortunately this isnt applying to links hard-coded inside of the post content. What do I have to change, so its working for every internal link:

add_filter( 'post_link', function( $url, $post ) {
    static $recursing = false;
    if ( $recursing ) {
        return $url;
    }
    $recursing = true;
    if ( ! function_exists( 'post_supports_amp' ) || ! post_supports_amp( $post ) ) {
        return $url;
    }
    if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
        $url = amp_get_permalink( $post->ID );
    }
    $recursing = false;
    return $url;
}, 10, 2 );



from change links on amp to link to amp

No comments:

Post a Comment