Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Move scripts and styles to functions.php and enqueue them there properly #18

Closed
wants to merge 2 commits into from

2 participants

@obenland

Since TwentyTwelve will serve as a best practice example for Theme Developers, I would be thrilled if we could move all scripts and styles to functions.php, to adhere to this guideline in the Theme Review process.

From what I understand, leaving the comment-reply script in header.php is technically still acceptable, but let's set a good example! :)

Maybe, to top it off, we could add a comment to that html5.js script in header.php, explaining that scripts wrapped in conditionals there, are okay.

@lancewillett
Collaborator

Thanks for this and your other two pull requests.

We discussed this already in core, see Nacin's comment here: http://core.trac.wordpress.org/ticket/19978#comment:4

I agree we should keep it in header.php for simplicity.

Also, a side note: default theme names have a space between "Twenty" and the number. (Twenty Twelve, not TwentyTwelve.) :)

@obenland

Thank you for your consideration, Lance!
I hope I'll get the chance to contribute in the future. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 9 deletions.
  1. +11 −2 source/functions/functions.php
  2. +0 −7 source/templates/header.php
View
13 source/functions/functions.php
@@ -192,12 +192,21 @@ function twentytwelve_admin_header_image() { ?>
endif;
/**
- * Enqueue scripts for front-end.
+ * Enqueue scripts and styles for front-end.
*
* @since Twenty Twelve 1.0
*/
function twentytwelve_scripts() {
- wp_enqueue_script( 'navigation', get_template_directory_uri() . '/javascripts/theme.js', array( 'jquery' ), '20130320', true );
+
+ // Styles
+ wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri() );
+ wp_enqueue_style( 'twentytwelve-fonts', 'http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,300,600,700' );
+
+ // Scripts
+ wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/javascripts/theme.js', array( 'jquery' ), '20130320', true );
+
+ if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
+ wp_enqueue_script( 'comment-reply' );
}
add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts' );
View
7 source/templates/header.php
@@ -44,14 +44,7 @@
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/javascripts/html5.js" type="text/javascript"></script>
<![endif]-->
-<?php
-if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
- wp_enqueue_script( 'comment-reply' );
-
-wp_enqueue_style( 'fonts', 'http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,300,600,700' );
-wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri() );
-?>
<?php wp_head(); ?>
</head>
Something went wrong with that request. Please try again.