ACF get_field break &lt; &gt; or <>

376 views Asked by At

I'm using ACF 5.9.1 and I'm trying to get a simply field text value with this string stored:

Mydomain.com - Support [email protected]

When I print the echo of

<?php echo get_field('my_text_field', 'options'); ?>

this is what I see:

Mydomain.com - Support

and obviously that is what I see on HTML source:

Mydomain.com - Support [email protected]

So every string between <> is treated such as an html node.

Is this a normal behaviour?

1

There are 1 answers

1
Giangel84 On

I fixed the issue by myself, I just escaped the string using the function esc_attr.

So to avoid "get_field" function treat <> (with any string inside) as HTML node, you only need to use this way:

<?php echo esc_attr( get_field('my_text_field', 'options') ); ?>

And it will be printed properly as plain text.