$30 off During Our Annual Pro Sale. View Details »

Bulletproof JavaScript for plugins and themes

Bulletproof JavaScript for plugins and themes

A look at using best practices and avoiding bad assumptions when writing JavaScript for WordPress plugins and themes.

Avatar for Natalie MacLees

Natalie MacLees

September 10, 2016
Tweet

More Decks by Natalie MacLees

Other Decks in Technology

Transcript

  1. wp_localize_script( 'fancy-slider', 'sliderText', array( 'next' => __( 'Next', 'fslide' ),

    'prev' => __( 'Prev', 'fslide' ), 'page' => __( 'Page', 'fslide' ), ) );
  2. function prefix_script_load() { if ( is_home() ) { wp_enqueue_script( 'myscript'

    ); } } add_action( 'wp_enqueue_scripts', 'prefix_script_load' );
  3. function prefix_fancy_shortcode( $atts ) { wp_enqueue_script( 'myscript' ); return '<p

    class="fancy">Some fancy shortcode HTML</p>'; } add_shortcode( 'fancy', 'prefix_fancy_shortcode' );
  4. ;(function ($, objectName, undefined) { var mainNav = function() {

    // This is a private function }; objectName.init = function() { // This is a public funciton }; }(jQuery, window.objectName = window.objectName || {})); jQuery(function(){ objectName.init(); });