WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields
ACF 4.0 wysiwyg - the_content filter (7 posts)

  1. wizzud
    Member
    Posted 1 year ago #

    ACF v4.0 has removed the the_content filter from the output of wysiwyg fields. Please tell me how I can re-apply that filter, so that things like my embedded videos will work again!

    http://wordpress.org/extend/plugins/advanced-custom-fields/

  2. muckyt
    Member
    Posted 1 year ago #

    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

  3. JsonB123
    Member
    Posted 1 year ago #

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

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

  4. wizzud
    Member
    Posted 1 year ago #

    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');
  5. JsonB123
    Member
    Posted 1 year ago #

    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.

  6. wizzud
    Member
    Posted 1 year ago #

    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.

  7. guddu1315
    Inactive
    Posted 1 year ago #

    @wizzud Thanks buddy you solved my problem

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic