Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WordCamp Phoenix 2013: WordPress 301: JavaScript

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

WordCamp Phoenix 2013: WordPress 301: JavaScript

A talk introducing JavaScript in general and how to correctly use JavaScript in WordPress.

Natalie MacLees

January 18, 2013

Transcript

55 slides
  1. About Me • Purple Pen Productions founder + principal •

    jQuery for Designers author • SoCal WP Users’ Group organizer • jQuery LA Users’ Group founder + organizer @nataliemac | nataliemac.com
  2. Including JavaScript header.php <head> <meta charset="<?php bloginfo( 'charset' ); ?>"

    /> <title><?php wp_title( '|', true, 'right' ); ?></ title> <script src="/wp-content/themes/twentytwelve/scripts/ my-script.js"></script> <?php wp_head(); ?> </head>
  3. Including JavaScript header.php <head> <meta charset="<?php bloginfo( 'charset' ); ?>"

    /> <title><?php wp_title( '|', true, 'right' ); ?></ title> <script src="/wp-content/themes/twentytwelve/scripts/ my-script.js"></script> <?php wp_head(); ?> </head>
  4. Including JavaScript header.php <head> <meta charset="<?php bloginfo( 'charset' ); ?>"

    /> <title><?php wp_title( '|', true, 'right' ); ?></ title> <script src="<?php bloginfo('template_directory'); ?>/ scripts/my-script.js"></script> <?php wp_head(); ?> </head>
  5. Including JavaScript header.php <head> <meta charset="<?php bloginfo( 'charset' ); ?>"

    /> <title><?php wp_title( '|', true, 'right' ); ?></ title> <script src="<?php bloginfo('template_directory'); ?>/ scripts/my-script.js"></script> <?php wp_head(); ?> </head>
  6. WP Helper Functions wp_register_script( $handle, $src, $deps, $ver, $in_footer );

    wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
  7. Including JavaScript functions.php function prefix_load_scripts() { ! wp_register_script( 'my-script', get_template_directory_uri()

    . '/scripts/my- script.js' ); ! wp_enqueue_script( 'my-script' ); } add_action( 'wp_enqueue_scripts', 'prefix_load_scripts' );
  8. Using Included Libraries functions.php function prefix_load_scripts() { ! wp_register_script( 'my-script',

    get_template_directory_uri() . '/scripts/my-script.js', array( 'jquery' ), '1.0', true ); ! wp_enqueue_script( 'my-script' ); } add_action( 'wp_enqueue_scripts', 'prefix_load_scripts' );
  9. superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a

    Child Theme I’m naming my child theme ‘superfish’
  10. superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a

    Child Theme collect all of our javascript files together
  11. superfish functions.php scripts custom.js hoverIntent.js superfish.js style.css Set up a

    Child Theme blank javascript file where we’ll write our script
  12. style.css /* Theme Name: Superfish Theme URI: http://purplepen.com Description: Child

    theme for the Twenty Twelve theme adding Superfish menus Author: Natalie MacLees Author URI: http://nataliemac.com Template: twentytwelve Version: 0.1.0 */ @import url("../twentytwelve/style.css");
  13. style.css /* Theme Name: Superfish Theme URI: http://purplepen.com Description: Child

    theme for the Twenty Twelve theme adding Superfish menus Author: Natalie MacLees Author URI: http://nataliemac.com Template: twentytwelve Version: 0.1.0 */ @import url("../twentytwelve/style.css");
  14. functions.php function superfish_load_scripts() { ... wp_register_script( 'superfish', get_stylesheet_directory_uri() . '/scripts/

    superfish.js', array( 'jquery', 'hoverintent' ), '1.0', true ); wp_register_script( 'custom-script', get_stylesheet_directory_uri() . '/scripts/custom.js', array( 'jquery', 'hoverintent', 'superfish' ), '1.3', true ); }

More Decks by Natalie MacLees

Other Decks in Technology