I have below code.echo $FileContents;shows the page which comes the php variable correctly, but the escape function which is <?php esc_html( $FileContents ); ?>didnt show anything.

How can I escape it correctly and show the page?

<?php global $redux_demo; ?>
<div class="row">
    <div class="col-md-12 ulockd-mrgn1210">
        <?php $FileContents = file_get_contents($redux_demo['text-location-service-details']); ?>
        <?php echo $FileContents; ?>
        <?php esc_html( $FileContents ); ?>

1 Answer 1


Well, esc_html() doesn't echo/display the return value (escaped string), so you need to call echo manually:

echo esc_html( $FileContents );


If you actually want to filter the list of allowed HTML tags in the variable's value, then you can use the WordPress' KSES functions like wp_kses_post() and wp_kses_data():

echo wp_kses_post( $FileContents );
echo wp_kses_data( $FileContents ); // allows basic HTML by default
  • when I use it like you said, it print html as text like source code, not visual Commented Jun 16, 2020 at 3:27
  • That's how esc_html() works. Your question was also about showing the escaped value, right? But check the revised answer and see if it helps.
    – Sally CJ
    Commented Jun 16, 2020 at 3:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.