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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.