@john2gr It looks like you may be using Yoast. If so you may be encountering the below issue with the meta description tag not appearing:
https://github.com/Yoast/yoastseo-amp/issues/27
Can you try the below, added to your themes functions.php file or preferably a custom plugin??
add_action( 'amp_post_template_head', 'add_meta_description' );
function add_meta_description() {
$meta_description = get_post_meta(get_the_ID(), '_yoast_wpseo_metadesc', true);
echo '<meta name="description" content="' . $meta_description . '">';
}
Alternatively you can use a function similar to the above but manually include your own meta description, as opposed to a Yoast variable.
I noticed also you’re using an AMP compatible theme. While you have have some plugins that are not fully AMP compatible did you test out your site when using the plugin in transitional
or standard
mode?
Hi James,
Unfortunately, this code doesn’t work. We haven’t tested the other modes but what are the plugins that are not compatible with AMP?
@john2gr I’m not sure what plugins you have installed. If the plugins you have installed don’t output custom JavaScript in the front end of your website you have be ready for transitional
mode AMP.
In relation to the title not appearing in your reader mode templates have you made any changes to the AMP reader mode templates?
@john2gr The title
tag is missing from head
. Were the Reader Mode templates modified?
This Section in the AMP plugin site describes template customization: https://amp-wp.org/documentation/how-the-plugin-works/classic-templates/
In the classic Reader mode templates, the document title is normally output via the amp_post_template_add_title() function. This function is added to output at the amp_post_template_head
action, which need to be preserved in any overridden template. This is the code that is expected to be present: https://github.com/ampproject/amp-wp/blob/2bfb9bb9450d11a652827da39533746bc6e5357c/templates/html-start.php#L31-L39
Hi albertomedina. That’s strange, nope. I’ve just completely removed/uninstalled the plugin and re-installed it.
The html-start.php and amp-post-template-functions.php are exactly the same with what Weston Ruter provided. Here is what the header.php of AMP currently is. Again, this is a completely fresh install of the plugin.
<?php
/**
* Header template part.
*
* 🚫🚫🚫
* DO NOT EDIT THIS FILE WHILE INSIDE THE PLUGIN! Changes You make will be lost when a new version
* of the AMP plugin is released. You need to copy this file out of the plugin and put it into your
* custom theme, for example. To learn about how to customize these Reader-mode AMP templates, please
* see: https://amp-wp.org/documentation/how-the-plugin-works/classic-templates/
* 🚫🚫🚫
*
* @package AMP
*/
/**
* Context.
*
* @var AMP_Post_Template $this
*/
$this->load_parts( [ ‘header-bar’ ] );
-
This reply was modified 3 years, 11 months ago by john2gr.
-
This reply was modified 3 years, 11 months ago by john2gr.
Yeah, it appears that for some reason <title> is missing from the AMP (it is present in the non-AMP page). Again, this is a fresh install of AMP so I don’t know why it’s happening. How can we add the <title> to the header for the AMP? (both html-start.php and amp-post-template-functions.php are the default ones).
What other plugins do you have active?
Does your theme have an amp directory is in it?
Hi Weston,
Here are our active plugins: https://i.imgur.com/EhuQgMt.jpg
We are using a child theme of Twenty Fourteen. I don’t think Twenty Fourteen has an amp directory.
-
This reply was modified 3 years, 11 months ago by john2gr.
The best recommendation I have is to try deactivating plugins one-by-one to see if deactivating one causes the title
tag to reappear.
Hi Weston,
We can now confirm that this is due to YOAST SEO. When we disabled it, the title appeared. However, YOAST SEO is a must-have plugin for us. The workaround that James suggested does not work.
That’s very strange.
I can indeed see that Yoast is removing the title: https://github.com/Yoast/wordpress-seo/blob/fbf1f3243776b983c176dff7fd66bdad9e8aa5ff/src/integrations/third-party/amp.php#L56
For some reason Yoast’s Title_Presenter
is not running. Apparently it is not included among the $presenters
as gathered here:
https://github.com/Yoast/wordpress-seo/blob/fbf1f3243776b983c176dff7fd66bdad9e8aa5ff/src/integrations/front-end-integration.php#L248-L274
Make sure you’ve configured the SEO Title in your Yoast settings, I suppose. I’m not really sure why Yoast isn’t running here.
It looks like this is a known issue: https://github.com/Yoast/wordpress-seo/issues/15100
There is a potential workaround here: https://github.com/Yoast/wordpress-seo/issues/15100#issuecomment-627334462
Otherwise, you’ll need to reach out to Yoast for more support here.
Unfortunately that workaround (the last one from Djennez) introduces two <title> on non-AMP pages :/
Yeap, this works correctly and there are no more duplicate <title> tags on non-AMP pages. Thanks Weston 😀