plugins - Add keywords meta to index.php page

I've created a php script to add keywords to my posts and pages. My question is about the wordpress index page. Is

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.

Share Improve this question asked Mar 26, 2019 at 13:05 newbWPdevnewbWPdev 311 bronze badge 6
  • 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 the is_single() and is_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
 |  Show 1 more comment

1 Answer 1

Reset to default 1

I 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) . '">';
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745655084a4638496.html

相关推荐

  • plugins - Add keywords meta to index.php page

    I've created a php script to add keywords to my posts and pages. My question is about the wordpress index page. Is

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信