• Resolved nicolaspl

    (@nicolaspl)


    Hello,

    On my AMP pages, all links have “/amp” at the end without checking if AMP version exist.
    Do you have a simple solution to avoid this ?

    Thank you

    • This topic was modified 4 months, 3 weeks ago by nicolaspl.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support Milind More

    (@milindmore22)

    Hello @nicolaspl

    Thank you for reaching out to us, it seems the AMP is active on pagination page as we can find

    <link rel="amphtml" href="https://www.monpetitforfait.com/actualites/page/2/amp"> on non-AMP pages,

    if you want to disable the amp on pagination, we will recommend checking Dashboard->AMP->Supported templates settings, please check our documentation to learn more.

    We hope this helps!

    Thread Starter nicolaspl

    (@nicolaspl)

    Thank you for your feedback
    We do not want to unactivate fort this post type.
    Only not have “/amp” for non-AMP pages. As in our navigation, mainly pages are non-AMP pages but have the “/amp”.

    Plugin Support Milind More

    (@milindmore22)

    Hello @nicolaspl

    As I mentioned in my previous reply, you can toggle off the templates where you do not want AMP pages

    To deactivate, Login as Admin->Dashboard->AMP->Settings->Supported templates and toggle off categories/ tags archive to remove those pages from AMP.

    We hope this helps!

    Thread Starter nicolaspl

    (@nicolaspl)

    Hello,

    Into doubt, I did what you explained but that’s not what I want.
    I didn’t say I wanted to disable my AMP pages, just “/amp” URLs in this pages.

    For exemple, in “https://www.monpetitforfait.com/actualites/page/2/amp” I want to keep this URL like this.
    Simply remove all “/amp” for pages that don’t have an AMP version.
    This URL “https://www.monpetitforfait.com/comparatif-forfaits-pas-chers/amp” is present on “https://www.monpetitforfait.com/actualites/page/2/amp” but not exist and create a redirection.

    For information, I have already looked if a hook could do the necessary and I only found this one “amp_to_amp_linking_element_excluded” but which would requires me to check on each URL is they have the AMP option activated which is quite heavy.

    Hope my explanation is clear.
    Thank you for your help.

    Plugin Support Milind More

    (@milindmore22)

    Hello @nicolaspl

    I understand you wanted AMP pages, but you don’t want pagination links to be AMP

    Please try adding the following code snippet in your theme functions.php or in a custom plugin

    add_filter(
    	'amp_to_amp_linking_element_excluded', 
    	function( $excluded, $url ) {
    		// find pagination urls.
    		if ( strpos( $url, 'page/' ) !== false ) {
    			return true;
    		}
    		return $excluded;
    	},
    	10,
    	2
    );
    Thread Starter nicolaspl

    (@nicolaspl)

    Not only pagination links, that’s where my problem lies.
    I need to check if all pages have the “AMP” option active.
    I already create a code snippet like yours when I was browsing your plugin code.

    As I thought, there is no simple solution to my case, I will check all “AMP” options for URLs present on “AMP” pages.

    Thank you for your time.

    /**
    * Remove "/amp" from URL without AMP version
    * @param $excluded
    * @param $url
    * @return bool
    */
    function remove_amp_from_url($excluded, $url) {
    if (!$excluded) {
    if (get_home_url() === trim($url, '/') || str_contains($url, '/page/')) {
    return true;
    }
    }

    return $excluded;
    }
    add_filter('amp_to_amp_linking_element_excluded', __NAMESPACE__.'\remove_amp_from_url', 10, 2);
    Thread Starter nicolaspl

    (@nicolaspl)

    Hello,

    Ideally, in my case, the pages “/page/*/amp” should not exist.
    It might be interesting to have a hook in the “amp_is_available” function to be able to manage if a particular page exists in AMP and avoid to use redirection with the “noamp” variable.

    Actually I use the hook “amp_supportable_post_types” like this.

    Have a good day.

    function amp_supportable_post_types($post_types) {
    return preg_match('/\/page\//', $_SERVER['REQUEST_URI']) === 1 ? [] : $post_types;
    }
    add_filter('amp_supportable_post_types', __NAMESPACE__.'\amp_supportable_post_types');
    • This reply was modified 4 months, 2 weeks ago by nicolaspl.
    • This reply was modified 4 months, 2 weeks ago by nicolaspl.
    Plugin Support Milind More

    (@milindmore22)

    @nicolaspl

    Glad you found the solution to your issues, I will mark this support topic as resolved.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.