Support » Plugin: Advanced Custom Fields » ACF 4.0 wysiwyg – the_content filter

Viewing 6 replies - 1 through 6 (of 6 total)
  • I am having the same problem too. Have been trying for hours to find a workaround without having to downgrade my plugin to work for now

    Have you tried applying the filter manually in your template? E.G:

    echo apply_filters('the_content', get_field('your_wysiwyg'));

    Applying the filter on the result of the get_field() call would run wpautop() and do_sortcode() twice. What I really wanted to do was get back to the documented Template usage of the Wysiwyg field :

    The API will return your content formatted for HTML (the same way that the_content() does)

    I eventually got around it by adding the following code to my child theme’s functions.php …

    function my_acf_format_value_for_api($value, $post_id, $field){
    	return str_replace( ']]>', ']]>', apply_filters( 'the_content', $value) );
    }
    function my_on_init(){
    	if(!is_admin()){
    		remove_all_filters('acf/format_value_for_api/type=wysiwyg');
    		add_filter('acf/format_value_for_api/type=wysiwyg', 'my_acf_format_value_for_api', 10, 3);
    	}
    }
    add_action('init', 'my_on_init');

    I believe that the documented usage of the Wysiwyg field on ACF needs to be updated due to the change in the changelog:

    [Removed] Removed the_content filter from WYSIWYG field

    I have a question about your solution though since you’re just applying the content filter in your function anyway, what’s the real difference between using that line I had for your template above and your function? How is calling apply_filters on my front-end template calling the wpautop() and do_shortcode twice?

    I’m confused by your statement.

    ACF adds a filter – acf/format_value_for_api/type=wysiwyg – to the retrieval of a wysiwyg field. The filter is acf_field_wysiwyg::format_value_for_api(), which runs wpautop() and do_shortcode(). So when you call get_field() on a wysiwyg field, that filter has already been applied. If you then apply the ‘the_content’ filters yourself, those filters include (re-)running wpautop() and do_shortcode(), and a host of other functions.

    guddu1315

    (@guddu1315)

    @wizzud Thanks buddy you solved my problem

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘ACF 4.0 wysiwyg – the_content filter’ is closed to new replies.