Implementing Metadata for an Archive Page When Yoast SEO Doesn’t Work

back to articles

While developing a corporate website for a client, I encountered a situation where the metadata for an archive page of a custom post type was not displayed through the SEO plugin. In my case, the Yoast SEO plugin was used, but for the archive pageservices titleAnddescriptionwere not displayed.

To solve the problem while still leaving easy editing for site managers, I implemented my own metadata management system using Advanced Custom Fields (ACF).

This approach is often used in corporate websites , where it is important to give the client the opportunity to edit SEO fields through the administrative panel.

Creating SEO fields via ACF

First I createdOption Pagein ACF, where the SEO fields for the archive page will be stored.

INfunctions.phpadd a settings page:

After that inACF Field Groupcreate two fields:

  • services_seo_title
  • services_seo_description

These fields will be available in the admin panel on the settings page.

Adding SEO Title via functions.php

Next, we need to intercept the Yoast SEO filter and substitute our values ​​from ACF.

How the code works

  • Filter in usewpseo_title.
  • Checks whether the page is an archiveservices.
  • Get the value from ACF usingget_field.
  • If the field is filled in, it replaces the standard SEO title.
  • Adding Meta Description
  • Meta description is implemented in a similar way.

Adding Meta Description

Meta description is implemented in a similar way.

Operation logic

  • filter is usedwpseo_metadesc
  • archive page is checked
  • pulls up description from ACF
  • if the field is filled in, it is used as a meta description

Result

As a result, the client receives a convenient interface for editing SEO metadata:

Админка WordPress → Theme Settings → Services Page

Here you can edit:

  • SEO Title
  • Meta Description

Benefits of this approach

  • SEO fields can be edited without access to the code
  • the solution works even if the SEO plugin does not process archives correctly
  • convenient to use on corporate websites
  • Easily scales to other archive pages