Help about Escaping

Here’s just a few examples of what escaping looks like: Escaping URLS: <?php echo esc_url( home_url() ); ?> Escaping Content <?php echo esc_html( get_the_title() ); ?> Escaping Attributes <?php echo esc_attr( $my_class ); ?> Escaping Content but keep HTML <?php echo wp_kses_post( get_the_content() ); ?> Escaping Emails <?php echo sanitize_email( $email_address ) ); ?> For … Read more

file_get_contents | escaping doesnt show the page

Well, esc_html() doesn’t echo/display the return value (escaped string), so you need to call echo manually: echo esc_html( $FileContents ); Update 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( … Read more

How to correctly escape an echo

Escaping is only necessary when you have no full control of the the thing you are echoing. So as long as $folder is a variable that you have defined yourself, there’s no real need to escape. But if there is user input involved, there is esc_html, to be used as follows: echo esc_html (“this input … Read more

wordpress post not showing my “” text>?

You have to escape th < and the > with &lt; and &gt;, otherwise WordPress will remove the “unknown tags”. You could also filter pre_kses to change the output before it gets stripped. add_filter( ‘pre_kses’, function( $str ) { // find and escape < and > on specific positions, then return $str; });