Home Forums Add-ons Flexible Content Field Yoast SEO & ACF Reply To: Yoast SEO & ACF

  • The exact code I’ve put into my ‘functions.php’ looks like this:

    add_filter( 'wpseo_pre_analysis_post_content', 'filter_yoasts_wpse_119879', 10, 2 );
    function filter_yoasts_wpse_119879( $content, $post )
    	if( have_rows('project_page') ):
    	     // loop through the rows of data
    	    while ( have_rows('project_page') ) : the_row();
    	        if( get_row_layout() == 'intro' ):
    	        	$field1 = get_sub_field( 'text' );
    	        if( get_row_layout() == 'in-depth' ):
    	        	$field2 = get_sub_field( 'in_depth' );
        $fields = $field1 . ' ' . $field2;
        return $content . $fields;

    As you can see, my Flexible Layout is called ‘project_page’.
    The first ‘while’ statement checks if there are any rows, and if so, get the one with the names ‘intro’ and ‘in-depth’, and put the content (‘text’ and ‘in_depth’) of the corresponding sub fields in a variable labeled $field1 and $field2.
    The last thing I do is combine these two variables into one ($fields) and return that.
    I’m not a PHP guru, absolutely not. But looking at different pieces of code I came up with this one. I do not know if it is very ‘clean’ or efficient PHP-code, but it works (for me)
    Actually, this function is based on the one you posted earlier.