How to add meta tags to a WordPress archive page?

by alvera_smith , in category: SEO , a year ago

How to add meta tags to a WordPress archive page?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

2 answers

Member

by mabelle , a year ago

@alvera_smith 

To add meta tags to a WordPress archive page, you can follow these steps:

  1. Login to your WordPress dashboard.
  2. Go to Appearance > Theme Editor.
  3. Find the file archive.php or category.php in the right-hand panel (this will depend on the type of archive page you want to add meta tags to).
  4. Add the following code to the head section of the archive.php or category.php file:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<?php if (is_category()) : ?>
    <meta name="description" content="YOUR META DESCRIPTION HERE">
    <meta name="keywords" content="YOUR META KEYWORDS HERE">
<?php elseif (is_tag()) : ?>
    <meta name="description" content="YOUR META DESCRIPTION HERE">
    <meta name="keywords" content="YOUR META KEYWORDS HERE">
<?php elseif (is_author()) : ?>
    <meta name="description" content="YOUR META DESCRIPTION HERE">
    <meta name="keywords" content="YOUR META KEYWORDS HERE">
<?php elseif (is_date()) : ?>
    <meta name="description" content="YOUR META DESCRIPTION HERE">
    <meta name="keywords" content="YOUR META KEYWORDS HERE">
<?php elseif (is_search()) : ?>
    <meta name="description" content="YOUR META DESCRIPTION HERE">
    <meta name="keywords" content="YOUR META KEYWORDS HERE">
<?php endif; ?>


  1. Replace "YOUR META DESCRIPTION HERE" and "YOUR META KEYWORDS HERE" with the actual description and keywords you want to use for your archive page.
  2. Click the "Update File" button to save the changes.


Note that this will add the same meta description and keywords to all archive pages on your site. If you want to have different meta tags for different archive pages, you'll need to modify the code accordingly, either by using different conditionals or by adding custom fields to your archive pages.

by ervin.williamson , 5 months ago

@alvera_smith 

Please note that modifying theme files directly can be risky and may result in losing changes during future theme updates. It is recommended to create a child theme or use a plugin to add meta tags to your WordPress archive pages.


Here is an alternative method using a plugin called Yoast SEO:

  1. Install and activate the Yoast SEO plugin from the WordPress.org plugin repository.
  2. Once activated, go to SEO > Search Appearance in your WordPress dashboard.
  3. Click on the "Archives" tab.
  4. Customize the meta description and keywords for the different archive types (categories, tags, authors, date-based archives, and search) by filling in the appropriate fields.
  5. Save the changes.


The Yoast SEO plugin will automatically add the specified meta tags to your archive pages based on the settings you have configured.


Using a plugin like Yoast SEO not only makes it easier to manage meta tags for archive pages, but it also provides additional SEO features and optimizations for your WordPress site.