Created
April 5, 2017 15:02
-
-
Save daylik/59a4947b21df6aeadda18b3c1c799fe9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//### STYLES | |
function include_style( $style_name, $file, $array = '', $is_child){ | |
if( $is_child || $is_child == 'child'){ | |
$file_uri = get_stylesheet_directory_uri() . $file; | |
$file_path = get_stylesheet_directory() . $file; | |
} else { | |
$file_uri = get_template_directory_uri() . $file; | |
$file_path = get_template_directory() . $file; | |
} | |
wp_enqueue_style( $style_name, | |
$file_uri, | |
array( $array ), | |
filemtime( $file_path) | |
); | |
} | |
//### SCRIPTS | |
function include_script( $script_name, $file, $array = '', $is_footer, $is_child){ | |
if( $is_footer == 'header' || $is_footer == '' ){ $is_footer = false; } | |
elseif( $is_footer == 'footer'){ $is_footer = true; } | |
if( $is_child || $is_child == 'child'){ | |
$file_uri = get_stylesheet_directory_uri() . $file; | |
$file_path = get_stylesheet_directory() . $file; | |
} else { | |
$file_uri = get_template_directory_uri() . $file; | |
$file_path = get_template_directory() . $file; | |
} | |
wp_register_script( $script_name, | |
$file_uri, | |
array( $array ), | |
filemtime( $file_path), | |
$is_footer ); | |
wp_enqueue_script( $script_name ); | |
} | |
//### Active | |
function my_styles_and_scripts(){ | |
include_style( 'style-1', '/css/style_1.css'); | |
include_style( 'style-2', '/css/style_2.css'); | |
include_style( 'style-3', '/css/style_3.css'); | |
include_style( 'style-4', '/css/style_4.css', 'style-1'); | |
include_style( 'style-5', '/css/style_5.css', 'style-1', 'child'); | |
//in header | |
include_script( 'jq-plugin-1', '/js/jq_plugin_1.js', 'jquery'); | |
include_script( 'jq-plugin-2', '/js/jq_plugin_2.js', 'jquery', 'header', 'child'); | |
include_script( 'jq-plugin-3', '/js/jq_plugin_3.js', 'jquery', false, 'child'); | |
//in footer | |
include_script( 'jq-plugin-4', '/js/jq_plugin_4.js', 'jquery', 'footer'); | |
include_script( 'jq-plugin-5', '/js/jq_plugin_5.js', 'jquery', true); | |
} | |
add_action( 'wp_enqueue_scripts', 'my_styles_and_scripts' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment