Filtering 'the_content', but with Advanced Custom Fields

I'm using a str_replace to change the_content, using WordPress' default 'the_content'.

However, this does not seem to affect anything that has been submitted through the Advanced Custom Fields plugin.

My original function, that works with default WordPress editor:

function same_youtube_options($content) {
  return str_replace("rel=0&", "rel0&theme=light&autohide=1&showinfo=0&controls=1&", $content);
}
add_filter('the_content', 'same_youtube_options');

And this, adjusted for the Advanced Custom Fields:

function same_youtube_options_controls_acf($field) {
  $field = get_sub_field('iframe_url'); 
    return str_replace("rel=0&", "rel0&&autohide=1&showinfo=0&controls=1&", $field);
}

add_filter('acf/load_field/name=iframe_url', 'same_youtube_options_controls_acf');

However, the latter does not work. It simply removes the field from the page. Would anyone know how to use these filters correctly?

Answers


Try this:--

function same_youtube_options_controls_acf($value, $post_id, $field )
{
    // run the_content filter on all textarea values
    $value = apply_filters('the_content',$value);
    return $value;
}
add_filter('acf/load_value/name=iframe_url', 'same_youtube_options_controls_acf', 10, 3);

This hook will replace you custom field value with the_content filter.


Need Your Help

Get bytes from a std::vector<bool>

c++ stl

I have something like the following, and after populating it with a arbitrary number of bits, I need to get the bytes to write out to a file. I don't see a way to do this and it seems useful, so I ...