Skip to content Skip to navigation
Back to the main support

How to integrate Advanced Custom Fields (ACF) with SEOPress

SEOPress allows you to easily inject many types of data into your SEO metadata. In this guide, we will explain how to use the values from your custom fields created with the third-party Advanced Custom Fields extension.

Use “simple” custom fields in your SEO metadata

By default, a custom field can be used in a meta via this dynamic variable:

%%_cf_your_custom_field_name%%

Simply replace your_custom_field_name with the name/key of your custom field:

%%_cf_seo_title%%

This variable can be used in title tags, meta description, social (Open Graph / X) etc. It covers most field types in the Advanced Custom fields extension that use this function to be called:

get_field('field_name');

Use ACF Options Page Custom Fields in Your SEO Metadata

If you build options pages with ACF, the function to retrieve stored data is:

get_field('field_name', 'option');

By default, you will not be able to inject these into your SEOPress metadata. We will need to create a new custom dynamic variable whose code is:

Copy and paste this snippet of code into your functions.php file or into a must-use plugin.

Then replace in the code:

  • the names and keys given to the dynamic variables by those desired (lines 2,3, 18 and 19)
  • the names of the ACF fields when called via get_field() (lines 10 and 11)
  • your text-domain by yours for the translation (lines 18 and 19)

Below is an example with an options page created in ACF and 2 text fields:

Options page created with Advanced Custom Fields
Options page created with Advanced Custom Fields
Creation of 2 text fields with Advanced Custom Fields
Creation of 2 text fields with Advanced Custom Fields

Then the result in the SEO metabox and the Google preview showing our values dynamically retrieved from the ACF options page:

Using ACF fields from options pages in the SEOPress metabox
Using ACF fields from options pages in the SEOPress metabox

If you use the universal metabox, you will need to adapt the code as mentioned here to see the dynamic variable appear in the drop-down list. It remains optional to use it.