admin管理员组文章数量:1026989
I've created a php script to add keywords to my posts and pages. My question is about the wordpress index page. Is there a way to add the <meta name="keywords">
tag also to the home of my wordpress installation? I didn't set a static page, this because I've created a custom theme for my website.
I've created a php script to add keywords to my posts and pages. My question is about the wordpress index page. Is there a way to add the <meta name="keywords">
tag also to the home of my wordpress installation? I didn't set a static page, this because I've created a custom theme for my website.
1 Answer
Reset to default 1I guess you use metadata to store keywords for other pages. One way if to use some page for the source of homepage keywords.
Other is to add theme option for home page keywords:
https://blog.templatetoaster/wordpress-settings-api-creating-theme-options/
Afterwards:
add_action('wp_head', 'my_wp_head'));
function my_wp_head() {
if ( is_front_page() ) {
$keywords = get_option('homepage_keywords');
echo '<meta name="keywords" value="' . esc_attr($keywords) . '">';
}
}
I've created a php script to add keywords to my posts and pages. My question is about the wordpress index page. Is there a way to add the <meta name="keywords">
tag also to the home of my wordpress installation? I didn't set a static page, this because I've created a custom theme for my website.
I've created a php script to add keywords to my posts and pages. My question is about the wordpress index page. Is there a way to add the <meta name="keywords">
tag also to the home of my wordpress installation? I didn't set a static page, this because I've created a custom theme for my website.
- How are you adding meta tags to your posts and pages - writing them in a wp_head hook? Won't the same mechanism work for the front page? Are you having trouble detecting that you're on the front page, or storing / building the list of keywords to write, or something else? – Rup Commented Mar 26, 2019 at 13:12
-
I'm using the
add_action('wp_head', array($this, 'my_function'), 1);
, so basically it's the default wordpress hook to manipulate the head content. I'm not checking if the page is homepage but I'm only using theis_single()
andis_page()
functions to echo the<meta name="keywords">
tag. The tags are the standard tags that is possible to add within every post or page if the taxonomy is registered. – newbWPdev Commented Mar 26, 2019 at 13:21 -
You should be able to use
is_front_page()
to detect the homepage, though if you're using meta keywords for SEO, I'd suggest reading up on why most people discourage it. There are some use cases where they can be helpful, such as when you have a custom search engine that picks them up. – WebElaine Commented Mar 26, 2019 at 13:26 -
I know about, but the problem is that I can't set the keywords for the index page like other pages, this because the
index.php
file is part of my custom template. – newbWPdev Commented Mar 26, 2019 at 13:28 - "because the index.php file is part of my custom template" - why does that matter? Do you mean you're not calling wp_head in your template? – Rup Commented Mar 26, 2019 at 14:18
1 Answer
Reset to default 1I guess you use metadata to store keywords for other pages. One way if to use some page for the source of homepage keywords.
Other is to add theme option for home page keywords:
https://blog.templatetoaster/wordpress-settings-api-creating-theme-options/
Afterwards:
add_action('wp_head', 'my_wp_head'));
function my_wp_head() {
if ( is_front_page() ) {
$keywords = get_option('homepage_keywords');
echo '<meta name="keywords" value="' . esc_attr($keywords) . '">';
}
}
本文标签: pluginsAdd keywords meta to indexphp page
版权声明:本文标题:plugins - Add keywords meta to index.php page 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745655083a2161550.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
add_action('wp_head', array($this, 'my_function'), 1);
, so basically it's the default wordpress hook to manipulate the head content. I'm not checking if the page is homepage but I'm only using theis_single()
andis_page()
functions to echo the<meta name="keywords">
tag. The tags are the standard tags that is possible to add within every post or page if the taxonomy is registered. – newbWPdev Commented Mar 26, 2019 at 13:21is_front_page()
to detect the homepage, though if you're using meta keywords for SEO, I'd suggest reading up on why most people discourage it. There are some use cases where they can be helpful, such as when you have a custom search engine that picks them up. – WebElaine Commented Mar 26, 2019 at 13:26index.php
file is part of my custom template. – newbWPdev Commented Mar 26, 2019 at 13:28