admin管理员组文章数量:1289352
We have this web and we added meta tags in different pages using this way.
<Helmet>
<title>THIS IS TITLE</title>
<meta
name="description"
content="THIS IS CONTENT" />
</Helmet>
I see the change in title when I hit the route for this page. I see meta tags in elements but I don't see meta tags of that page in view page source. What's wrong and how can we solve this. As per our seo expert, it should e in view page source.
Note: It is a client side rendered app.
We have this web and we added meta tags in different pages using this way.
<Helmet>
<title>THIS IS TITLE</title>
<meta
name="description"
content="THIS IS CONTENT" />
</Helmet>
I see the change in title when I hit the route for this page. I see meta tags in elements but I don't see meta tags of that page in view page source. What's wrong and how can we solve this. As per our seo expert, it should e in view page source.
Note: It is a client side rendered app.
Share Improve this question edited Jun 19, 2023 at 16:49 fatihyildizhan 8,8327 gold badges67 silver badges91 bronze badges asked Feb 29, 2020 at 16:57 horrible_nerdhorrible_nerd 1251 gold badge4 silver badges10 bronze badges2 Answers
Reset to default 9This is because react (and react-helmet) are front-end tools (unless you are doing server side rendering) and the view source browser's feature is showing you the original source downloaded from the server, while the "inspect" action is displaying the actual DOM.
What this means?
Your users will see new meta tags normally, and so Google Bot (as recently started to execute JavaScript) but not other crawling service or search engines.
If you want to target other search engines: do SSR.
you can change meta data in viewsource code also all you need to do is that after the build is pleted change index.html to index.php and add another file called metas.php
in metas.php you can simple write php code like this
<?php
$url = "https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$escaped_url = htmlspecialchars( $url, ENT_QUOTES, 'UTF-8' );
if ($escaped_url === 'https://example.') {
$pageTitle = 'title';
$metaDescription = 'some text';
$canonical ='https://example.';
}
else if ($escaped_url === 'https://example.') {
$pageTitle = 'title';
$metaDescription = 'some text';
$canonical ='https://example.';
}
else{
$pageTitle = '404';
$metaDescription = 'some text';
$canonical ='https://example.';
}
?>
and in you index.php include the metas.php file on top and call these variables which is in the metas.php file like this:-
<title><?php echo $pageTitle; ?></title>
<meta name="description" content="<?php echo $metaDescription; ?>" />
<link rel="canonical" href="<?php echo $canonical; ?>">
本文标签:
版权声明:本文标题:javascript - React helmet not showing meta tags in view page source but shows in element on inspect - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741390725a2376087.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论