<< back to code examples

WordPress Custom Functions.php

This is an example of how I enque my style sheets and scripts using WordPress Hooks . Loading them through the functions.php file with PHP increases site speed and efficiency. You will see a noticeable difference.

<?php

// Load External CSS
 function theme_styles() {

   wp_enqueue_style( 'text', get_template_directory_uri() . '/css/frontpage.css' );
   wp_enqueue_style( 'home', get_template_directory_uri() . '/css/content.css' );
   wp_enqueue_style( 'shadowbox', get_template_directory_uri() . '/shadowbox/shadowbox.css' );    wp_enqueue_style( 'main', get_template_directory_uri() . '/style.css' );
   wp_enqueue_style( 'responsive', get_template_directory_uri() . '/css/responsive.css' );     wp_enqueue_style( 'openSans', 'http://fonts.googleapis.com/css?family=Open+Sans:400,600,300,700,800' );

 }

// Load Javascript
function theme_js() {

   // Register first then enqueue on certain pages with a conditional
   wp_register_script( 'theme', get_template_directory_uri() . '/js/theme.js', array('jquery'), '', true );
   wp_enqueue_script( 'theme' );

   wp_register_script( 'shadowbox', get_template_directory_uri() . '/shadowbox/shadowbox.js', array('jquery'), '', true );
   wp_enqueue_script( 'shadowbox' );

   wp_register_script( 'front', get_template_directory_uri() . '/js/front.js', array('jquery'), '', true );
   wp_enqueue_script( 'front' );

}

// Add above Functions

   add_action( 'wp_enqueue_scripts', 'theme_js' );

   add_action( 'wp_enqueue_scripts', 'theme_styles' );

?>

More Code Projects