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' );
endif;
if( get_row_layout() == 'in-depth' ):
$field2 = get_sub_field( 'in_depth' );
endif;
endwhile;
endif;
$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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.