• Closed by: Fred
  • Closed on: 28.05.21, 11:26
  • Reason: Closed
  • Comment: Glad to help!

Ticket #21478 - Exclude some pages from amp version

Hi,

I need to exclude some pages from AMP version in alysum theme.

In other words when users navigate the site from mobile device I need to show all pages in AMP version EXCEPT some specific page IDS.

Can you indicate a method to obtain this result?

Thanks.

Comments

Fred 10 May 2021, 22:34

Hi, Rosita.
Open the file /modules/pkamp/pkamp.php
Find the line

if ($redirect && $enabled && ($canonical != $ampLink)) {

add following code before

if ($page == 'YOUR_PAGE_NAME') {
    $redirect = false;
}
Rosita Paparelli 11 May 2021, 12:27

Hi, thanks for the reply.
I have forgotten to specify that those pages are all CMS pages.
So what do I have to insert at the place of “YOUR_PAGE_NAME”? The permalink of the page ($cms.link_rewrite)? The meta title? The content of the variable $page.page_name (which is “cms”…).
Thank you.

Fred 11 May 2021, 22:23

try this

if ($page == 'cms') {
Rosita Paparelli 13 May 2021, 10:00

Sorry but it doesn’t work… I need to exclude only some pages, not every cms page…

Rosita Paparelli 13 May 2021, 10:00

Sorry but it doesn’t work… I need to exclude only some pages, not every cms page…

Fred 13 May 2021, 10:01

It requires deeper code customisations. We have too much tickets and not available for custom works

Rosita Paparelli 14 May 2021, 10:56

Hi,
is there an additional price to pay for this kind of customization?

Fred 14 May 2021, 11:51

I would do that for free, but this week we have too much tickets
Maybe on weekend

Rosita Paparelli 14 May 2021, 16:56

Ok, thanks, I look forward for a reply.

I have already created a custom child theme with the module/pk_amp directory inside.

Best regards.

Fred 15 May 2021, 13:40

try this

if (Tools::getValue('id_cms') == 1) {
  $redirect = false;
}

where “1” is an ID of your page

Rosita Paparelli 17 May 2021, 15:51

Sorry but even this way it doesn’t work, you can check yourself visiting this page: https://www.lapiantadelte.it/shop/mobile/page/10-contattaci

Fred 17 May 2021, 23:47

Please update credentials in your profile https://support.promokit.eu/index.php?do=myprofile to access to your server through FTP

Rosita Paparelli 18 May 2021, 12:26

Done: I have updated the credentials.
Thank you.

Rosita Paparelli 18 May 2021, 14:28

Done: I have updated the credentials.
Thank you.

Fred 18 May 2021, 15:44

Something wrong here.
I edit the file /web/test_shop/modules/pk_amp/pk_amp.php but nothing is changed in the website

Rosita Paparelli 19 May 2021, 15:17

Hi: the file to edit is in the web/shop directory, as mentioned in our FTP credentials section, NOT in web/TEST_shop…

Fred 20 May 2021, 11:37

Now everything works fine.
If you will open the page https://www.lapiantadelte.it/shop/content/10-contattaci on mobile, you will not be redirected to AMP

Rosita Paparelli 20 May 2021, 14:34

Yes, now the page has no redirect. As I said above I need to exclude more than one page.
Did you modified the line you mentioned before inside pk_amp.php? Because it seems to me that the modification you made is elsewhere.
Can you tell me where to add some other pages ids?
Thank you!

Fred 20 May 2021, 14:36

The file I edit is

/modules/pk_amp/pk_amp.php

find the line

if (Tools::getValue('id_cms') == 10) {

Add more IDs like this

if (Tools::getValue('id_cms') == 10 OR Tools::getValue('id_cms') == 12) {
Rosita Paparelli 21 May 2021, 14:27

It’s very strange but it works only for page id 10, even if I added other pages… I believe it’s a matter of caching… I have tried to clear the cache but with no result, I have also tried clearing the file var/cache/prod/class_index.php but, again, with no result.

Fred 25 May 2021, 16:01

I just added page id 8 for example, and it works correctly, there is no redirect
https://www.lapiantadelte.it/shop/content/8-privacy-policy

Rosita Paparelli 26 May 2021, 09:23

Hi,
goodmorning can you please help me resolve the problem?
My client is very upset: he really needs to exclude also other pages from AMP version, and I can’t make the code you suggested work properly!
Can you please check yourself?
Thank you so much!

Fred 26 May 2021, 09:39

I just added page id 8 for example, and it works correctly, there is no redirect

https://www.lapiantadelte.it/shop/content/8-privacy-policy

Rosita Paparelli 27 May 2021, 11:19

Ok, now I understood: you have modified the core, I created a child theme… inside the child the modification doesn’t work… But this is another problem.
Thank you for the support so far.
Best regards.