Support

Account

Home Forums ACF PRO Add a class to the last paragraph tag of a wysiwyg field Reply To: Add a class to the last paragraph tag of a wysiwyg field

  • Ok i think i figured things out.

    function last_paragraph( $content ){
      if ( is_page( 222 ) ) {
        return preg_replace('/[\s\S]*\K(<p>)/', '<p class="mytrail">', $content, 1);
      } 
    }
    add_filter('acf_the_content', 'last_paragraph');

    I’ve set the function only to a certain page and on that page it targets only acf fields ( which are in my case only text fields, text areas and wysiwyg fields). Text fields and text areas don’t have any wrapping p tags therefor only wysiwyg fields are targeted. And with that small function it is possible that the user is able to add more paragraphs in each wysiwyg field and still the class is set on the last paragraph of each wysiwyg field.