Home Forums Front-end Issues Injecting class in content


Injecting class in content

  • Hello,
    I am trying to inject lass in my content and it’s working fine, but it’s not adding class in the custom field content. How do I do that?

    This code injects class into my content, not in acf content.

    //**Adding UL Li**//
    add_filter('the_content', 'ja_ul_class');
    function ja_ul_class($content)
        $string = '<ul';
        $replace = '<ul class="detail-list"';
        $content = str_replace( $string, $replace, $content );
        return $content;
  • The ACF fields are outsite the_content() value. you should try using acf-format_value.

    There is a great example here:

  • If you want to use the_content filter you need to use that acf_the_content filter for WYSIWYG fields

    add_filter('the_content', 'ja_ul_class');
    add_filter('acf_the_content', 'ja_ul_class');
  • I added this and it’s working fine. Is this way right or wrong?

    add_filter('acf/format_value', 'acf_ul_class');

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.