How to make a different description in <meta name="description" content="..." /> for different pages of the site on Wordpress? For main and for pages of articles. For categories and tags is not necessary. With what php code?

    2 answers 2

    Use the wordpress functions is_front_page() , is_single() , is_home() to determine which page you are on. Depending on the result of their execution, output the corresponding content in the meta tag.

    For example, a unique description for articles can be set as follows:

    1. When creating / editing an article, set the description in the "quote" field (if you do not see it - look in the upper right corner, click on "screen settings", put a check mark next to the "quote" field)

    enter a description in the "quote" field

    1. and further in the code

      <?php if (is_single()){ ?> <meta name="description" content="<?php the_excerpt(); ?>" /> <?php } ?>

    • yes, but if I need to specify a specific description for a particular article from the blog, for example, my description for url mysite.net/blog/article-1, another one for mysite.net/blog/article-2 ... - Beginner
    • maybe is_single ('mysite.net/blog/article-1'); - Beginner
    • but it doesn’t work out that way ... the same description gives the same - Beginner
    • Updated the answer. - alenkins 5:03 pm
    • Fine! Now everything turned out. - Beginner

    Use the plugin (Yoast Seo) [ https://wordpress.org/plugins/wordpress-seo/] . It allows you to set custom descriptors and titles for articles and not only.