Support

Account

Home Forums ACF PRO ACF PRO fields inside of Yoast – meta title and meta Description

Solving

ACF PRO fields inside of Yoast – meta title and meta Description

  • I am trying to get ACF custom fields from “options” to work inside of Yoast meta title and Meta Description.

    I used following code in 2016 and it worked then….in fucntions.php file.

    add_filter('wpseo_metadesc', run_short_codes_in_meta_desc, 137);
    
    function run_short_codes_in_meta_desc($metadesc)
    {
    return do_shortcode($metadesc);
    }
    
    add_filter('wpseo_title', run_short_codes_in_title, 136);
    
    function run_short_codes_in_title($title)
    {
    return do_shortcode($title);
    }

    I am not sure what I am doing wrong.
    your help is appreciated.

  • Shortcodes may not be usable in combination with that filter. As I understand it the value is already formatted by yoast before it is called and the shortcodes are likely already removed.

  • thanks John. I code for Yoast apparently has changed since then.

    This plugin was recommended by ACF support.
    https://wordpress.org/support/plugin/acf-content-analysis-for-yoast-seo

    I don’t see anything changing after adding that plugin.
    the shortcode formats I tried are:

    %%cf_VariableName%% and
    also regular custom options code from ACF –> [acf field="VariableName" post_id="options"]

    Any idea on what needs to be done after plugin installation? I am a bit surprised that this isn’t a bigger issue for people using ACF.

    am I missing something?

  • I don’t use that plugin, and I don’t really know what needs to be done.

    The first thing I would do is figure out what is being passed to your filters

    
    add_filter('wpseo_metadesc', run_short_codes_in_meta_desc, 137);
    
    function run_short_codes_in_meta_desc($metadesc)
    {
    echo "<!-- metadesc = $metadesc -->";
    return do_shortcode($metadesc);
    }
    
    add_filter('wpseo_title', run_short_codes_in_title, 136);
    
    function run_short_codes_in_title($title)
    {
    echo "<!-- title = $title -->";
    return do_shortcode($title);
    }
    

    then look in the page source to see what is being passed in.

  • I got this it to work thru paying for custom programming for it AND then fixed it myself to have it work correctly.

    Use following code inside of Yoast Meta Title and meta Description fields inside of pages/posts:

    
    %%VariableName%%
    

    I have only tested this with TEXT field in ACF PRO.

    Below is what goes into Functions.php

    
    if( function_exists('acf_add_options_page') ) {
    	
    	acf_add_options_page();
    	
    }
    
    $seo_variables = get_fields('options'); 
    if ( function_exists('get_fields') ){		
    	if( $seo_variables ) {
    		$seo_variables_array = array();
    		foreach( $seo_variables as $name => $value ):
    			$seo_variables_array[$name] = $value;		   
            endforeach;
    	}
    }
    
    function ss_get_all_values($var1){
    	global $seo_variables_array;
    //	echo($seo_variables_array[$var1]);
    	return $seo_variables_array[$var1];
    }
    
    function ss_register_custom_yoast_variables() {
    $seo_variables = get_fields('options');
    if ( function_exists('get_fields') ) {
    	if( $seo_variables ) {
    		$seo_variables_array = array();
    		foreach( $seo_variables as $name => $value ):		
    		    wpseo_register_var_replacement( $name, 'ss_get_all_values', 'advanced');
            endforeach;
    		}
    	}
    }
    
    // Add action
    add_action('wpseo_register_extra_replacements', 'ss_register_custom_yoast_variables');
    
  • I just want to say thank you for keeping the subject up to date.

    Apparently the current version of the module 3.0.1 works with TEXT variables other variables as well.

    %%cf_YOURTEXTVARIABLE%% works without any further edits or modifications.

  • I also want to thank you guys for keeping this open.


    @contact272
    do I need Yoast Premium? Because %%cf_varname%% is not working for me. I didn’t add the code from above yet though. I am using ACF Pro and the ACF Content Analysis for Yoast SEO.

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘ACF PRO fields inside of Yoast – meta title and meta Description’ is closed to new replies.