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:
Then the result in the SEO metabox and the Google preview showing our values dynamically retrieved from the ACF options page:
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.