I'm using a Text Area field within ACF.
I've set the "New Lines" option to "Automatically add paragraphs".
Here's how the PHP looks within my template file:
<?php
$notice = '<p>Some text.</p>';
$text = get_field( 'text', 'option' );
if ( $text ) {
echo str_replace( '<p>', '<p class="footer__paragraph">', $text );
}
else {
echo $notice;
}
?>
You'll see that I'm using str_replace
to add a custom CSS class to the <p>
tags.
I'd usually escape output, like so <?php echo esc_html( $text ); ?>
. This obviously doesn't work because autop adds a <p>
tag to each line.
Is it possible to escape output whilst maintaining my custom classes?