Support » Plugin: The SEO Framework » meta description from acf field

  • Resolved dasigna

    (@dasigna)


    hi there,

    case:
    currently transferring a site from an ugly multipurpose theme… doing this, we also ditched off ugly yo_st for TSF on this occasion.
    the site has hundreds of formerly inbuildt cpts which we managed to transfer also and fetching the former hardcoded information fields into acf.
    this is where the problem begins :/

    problem:
    formerly yst pulled the meta information from one of those custom fields. TSF obviously cant do this…
    so now we have all those cpts with nice acf-description-fields filled – but empty meta fields in TSF, sadly.

    question:
    is there any way to pull the information from those acf-text-fields into TSF for meta description? eighter via hook, filter or whatever?
    some research did not help so far.

    it would be a nightmare to fill all those fields again by hand πŸ™

    any advice or help highly appreciated – thanks in advance.

    • This topic was modified 1 year ago by dasigna. Reason: typos
    • This topic was modified 1 year ago by dasigna.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hello!

    Assuming acf-description-fields is the field you’re working with, this filter would do:

    add_filter( 'the_seo_framework_custom_field_description', function( $description, $args ) {
    
    	// A custom description is found for TSF already, let's skip further processing.
    	if ( $description ) return $description;
    
    	// If ACF is deactivated, skip further processing.
    	if ( ! function_exists( 'get_field' ) ) return '';
    
    	if ( null === $args ) {
    		// In the loop.
    		$description = get_field( 'acf-description-fields' );
    	} else {
    		// Out the loop.
    		if ( ! empty( $args['taxonomy'] ) ) {
    			// Taxonomy query... do something with 'taxonomy' and 'id'?
    		} else {
    			// Singular query.
    			$description = get_field( 'acf-description-fields', $args['id'] ) ?: '';
    		}
    	}
    
    	return $description;
    }, 10, 2 );

    I hope this does the trick πŸ™‚ Cheers!

    Thread Starter dasigna

    (@dasigna)

    … sorry for the late reply. being too busy.

    but yeah – absolutely great, that does the trick like a charm πŸ™‚

    big thanks!

    the only downer is that the description is now wrapped in <p>description from field</p> tags i couldnt get rid of so far…
    may this affect seo in any way? – apart from the fact it doesnt look quite sexy ;/

    any hint for that?

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi again πŸ™‚

    No problem!

    You can wrap wp_strip_all_tags( $field, true ) around the get_field() calls; that should get rid of the HTML tags.

    e.g.

    // In the loop.
    $description = wp_strip_all_tags( get_field( 'acf-description-fields' ), true );
    
    // Singular query.
    $description = wp_strip_all_tags( get_field( 'acf-description-fields', $args['id'] ), true ) );
    
    Thread Starter dasigna

    (@dasigna)

    thanks again. works of course.

    but as i discovered in addition: theres no extra HTML tag if the field is set to a simple text field. the tag only appears when its wysiwyg.

    great thing. who needs YST when there is TSF? πŸ™‚

    • This reply was modified 11 months, 3 weeks ago by dasigna.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘meta description from acf field’ is closed to new replies.