Please share the URL to your site.
Are you using multisite? Is there anything unique about your install?
Are you stripping out the generator meta tags from your site?
Yes. Like this in functions.php:
remove_action( 'wp_head', 'wp_generator' ); // remove wordpress version
-
This reply was modified 5 years, 11 months ago by
johnbenedict.
Sharing the Site Health info for your site would be helpful.
I can’t see from your site what version specifically of the the AMP plugin is running, what mode it is in, etc.
Nevertheless, I do see that your site is not entirely a standard setup. It has WordPress files installed in a wp subdirectory.
This is the logic for how the URL to the AMP version is being computed: https://github.com/ampproject/amp-wp/blob/1.5.3/includes/amp-helper-functions.php#L414-L443
Something seems to be going wrong here.
Not sure I want to post all the Site Health info here…
WordPress is 5.3.1 (right now)
AMP Plugin is 1.5.3 and is in Transitional Mode
Home URL: https://www.campsitephotos.com
Site URL: https://www.campsitephotos.com/wp
-
This reply was modified 5 years, 11 months ago by
johnbenedict.
OK, so then the amphtml link would be getting computed as follows: https://github.com/ampproject/amp-wp/blob/1.5.3/includes/amp-helper-functions.php#L495-L500
In short:
$amp_url = add_query_arg( amp_get_slug(), '', amp_get_current_url() );
Here’s the logic for amp_get_current_url():
https://github.com/ampproject/amp-wp/blob/1.5.3/includes/amp-helper-functions.php#L358-L376
Is this returning an invalid URL?
For example, is home_url( '/' ) not returning https://www.campsitephotos.com/?
If not, you may want to try patching it as follows:
- $url = preg_replace( '#(^https?://[^/]+)/.*#', '$1', home_url( '/' ) );
+ $url = preg_replace( '#(^https?://[^/]+)/.*#', '$1', trailingslashit( home_url() ) );
It could be you have a home_url filter that is trying to remove the trailing slashes?
Ok — that is very likely what is happening. I do see some uses of home_url doing something like this: home_url('/something')
I will look into fixing this within our own setup.
Thank you so much for you help troubleshooting this.
I’ll open an issue to make the logic in amp_get_current_url() more robust as well.
Please share the filter code that you’re using so that I can include it in the tests to ensure it fixes the issue you’re having.
In amp_get_current_url() we’ve found a simple change that fixed our issue:
Change this:
$url = preg_replace( ‘#(^https?://[^/]+)/.*#‘, ‘$1’, home_url( ‘/’ ) );
To this:
$url = rtrim(preg_replace( ‘#(^https?://[^/]+)/.*#‘, ‘$1’, home_url( ‘/’ ) ), ‘/’) . ‘/’;
What is the home_url filter code you are using that is causing the issue, though?