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