#StackBounty: #php #wordpress #amp-html #google-amp if is amp change internal links to amp version (WordPress)

Bounty: 100

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 );


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.