Skip to content

Instantly share code, notes, and snippets.

@verticalgrain
Last active October 3, 2017 18:43
Show Gist options
  • Save verticalgrain/b7c133e3032533aa88d07a7f9a6afc91 to your computer and use it in GitHub Desktop.
Save verticalgrain/b7c133e3032533aa88d07a7f9a6afc91 to your computer and use it in GitHub Desktop.
Wordpress cheatsheet
// TRANSLATION
// Translateable string, with escaping (in case there are special characters in one of the translations)
// This is the best choice since it catches and escapes any HTML that may be in the string
esc_html__( 'This is my string', 'translationdomain' );
esc_html_e( 'This is my string', 'translationdomain' );
// Retrieve the translation of a string
// Don't know why but apparently all three methods work
__( 'This is my string', 'translationdomain' )
_( 'This is my string', 'translationdomain' )
_e( 'This is my string', 'translationdomain' )
// Displays translated text that has been escaped for safe use in an attribute.
// i.e. <a aria-label="<?php esc_attr_e( 'View LinkedIn Profile', 'ms-newscenter' ); ?>">
esc_attr_e( 'some text', 'ms-newscenter' )
// Translateable string, with context as well as domain
// This is in case there are two identical strings that might not have identical translations
_x( 'Follow us:', 'Follow heading for social footer', 'ms-newscenter' )
// Encode visible text so that it's not rendered as browser markup
esc_html( 'http://whatnot.com' )
// rawurlencode - replace most alphanumeric characters with %XX
rawurlencode( 'http://whatnot.com' )
// Theme directory
get_stylesheet_directory_uri();
get_bloginfo('stylesheet_directory'); // Uses get_stylesheet_directory_uri() internally
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment