If you want to use the content of a user-defined field of the ACF plugin (Advanced Custom Fields) in the Yoast SEO Plugin, you can easily pass the value to Yoast as a template variable. It is therefore possible to use the content of the field in the SEO snippet as a title or meta description.

add_action('wpseo_register_extra_replacements', function () {
    wpseo_register_var_replacement('%%custom_template_variable%%', function () {
        global $post;

        $field = get_field_object('acf_field_name', $post->ID);

        return $field['value']->name;
    }, 'advanced', __('ACF Field Description'));

Show custom field in SEO snippet

Then you can use the template variable %%custom_template_variable%% to edit the SEO snippet in Yoast plugin.

Leave a Reply

Your email address will not be published. Required fields are marked *