Skip to content

Instantly share code, notes, and snippets.

@rajuahmmed
Last active December 5, 2016 14:41
Show Gist options
  • Save rajuahmmed/4a427d8b51165909cc68158e09347f1e to your computer and use it in GitHub Desktop.
Save rajuahmmed/4a427d8b51165909cc68158e09347f1e to your computer and use it in GitHub Desktop.
Escaping wordpress translated strings by https://www.cantothemes.com
<?php
/**
* Example of escaping __() function
*/
// Unescaped
echo __("Example String", "textdomain");
// Escaped from HTML : XSS safe
echo esc_html__("Example String", "textdomain");
// Escaped for Attribute : XSS safe
echo '<a href="#" title="'.esc_attr__("Example String", "textdomain").'">'.esc_html__("Example String", "textdomain").'</a>';
// Escaped from HTML with specified HTML Tag : XSS safe
$tags = array(
'h1' => array(
'class' => array();
)
);
echo wp_kses(__("Example String", "textdomain"), $tags);
/**
* Example of escaping _e() function
*/
// Unescaped
_e("Example String", "textdomain");
// Escaped from HTML : XSS safe
esc_html_e("Example String", "textdomain");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment