Support

Account

Home Forums Front-end Issues Disable Media AutoEmbed

Solved

Disable Media AutoEmbed

  • WordPress has an auto-embed feature, that automatically embeds a YouTube video, if the url appears on its own line – in any content.

    I needed to DISABLE this on my site, and I found a simple “remove_filter” hook (on http://wpengineer.com/2487/disable-oembed-wordpress/ ), which works for WP’s the_content() — but it does NOT work for ACF content.

    I tried using the same idea on an ACF hook, but this did not work.
    remove_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 );

    In the plugin file advanced-custom-fields/core/fields/wysiwyg.php, line #254, i found format_value_for_api(), which seems to add the standard filters that WP adds to the_content(), including ‘autoembed’, on line #261.

    So I’m trying to remove that filter, just as was done for the_content().

    Any ideas how to do that, or otherwise disable media auto-embeds in ACF content?

  • Hi @tex77

    Currently, the filters are added during the format_value_for_api which I should change to be added much earlier.

    Because of the current setup, it is not possible to remove the filter (sorry).

    Your only solution is to load the value without formatting:

    
    $value = get_field('field_name', false, false);
    

    Then apply the the_content filter to the value!

    
    $value = apply_filters('the_content', $value);
    

    Hope that helps

  • Thanks Elliot, yes that worked perfectly!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Disable Media AutoEmbed’ is closed to new replies.