Adding meta tag robots is an important step in optimizing a website. In WordPress, this can be easily achieved with the help of the function add_action. With this solution, we control which pages are to be indexed by search engines.
Why add a robots meta tag?
Adding meta tag robots allows you to manage the visibility of individual pages in search results. For example, we want to hide individual blog posts from indexing. In this case, we use noindex, nofollow. This security feature helps avoid duplicate content and protects private information.
How does the add_action function work in this context?
Function add_action adds the specified code to the section . pages. In our example, we check if the currently displayed page is a single entry using the is_single(). If so, addition of code Prevents search engine robots from indexing this page.
A practical implementation example
Here is the code that implements this in WordPress:
add_action('wp_head', function() { if (is_single()) { echo ''; } });
Therefore, we place this piece of code in the file functions.php
theme. This way, when a user visits a single entry, the robots meta tag is automatically added to the page header.
Benefits of this solution
Adding meta tag robots in WordPress brings several benefits:
- Control over indexing: We can specify precisely which pages to make visible to search engines.
- Protection of private content: We hide content that should not be publicly available.
- Improving SEO: We eliminate the problems of duplicate content, which positively affects the positioning of the site.
Summary
Adding this code in WordPress is a simple and effective way to manage your site's search engine visibility. Using the add_action and appropriate conditions, we can precisely control which parts of our site to index. This tool is invaluable for webmasters who care about SEO optimization and content security.