Created
May 21, 2017 05:18
-
-
Save LinzardMac/dc951d7fabf3fbeb1f10794c3130fecc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
// near line 347 | |
// build the attributes for the <script> tag | |
// including the type and src attrs. | |
$tag_attributes = []; | |
/** defaults always set **/ | |
$tag_attributes['type'] = "text/javascript"; | |
$tag_attributes['src'] = $src; | |
$tag_attributes_extra = $this->get_data( $handle, 'tag_attributes'); | |
if( $tag_attributes_extra ) | |
// combine 'must have' attrs with custom ones | |
$tag_attributes = wp_parse_args($tag_attributes_extra, $tag_attributes); | |
// chance for plugins, etc to filter attributes if needed. | |
apply_filters('script_tag_attributes', $tag_attributes, $handle ); | |
// add any additional attributes if set in the registration of script | |
foreach( $tag_attributes as $attr => $attr_val ){ | |
$attrs .= esc_attr($attr)."='".esc_attr($attr_val)."' "; | |
} | |
$tag = "{$cond_before}{$before_handle}<script {$attrs}></script>\n{$after_handle}{$cond_after}"; |
This file contains hidden or 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 | |
// around line 96 | |
function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $tag_attrs = false, $in_footer = | |
false ) { | |
global $wp_scripts; | |
if ( !is_a($wp_scripts, 'WP_Scripts') ) | |
$wp_scripts = new WP_Scripts(); | |
if ( $src ) { | |
$_handle = explode('?', $handle); | |
$wp_scripts->add( $_handle[0], $src, $deps, $ver ); | |
// set the tag_attributes as 'extra' data | |
$wp_scripts->add_data($_handle[0], 'tag_attributes', $tag_attrs); | |
if ( $in_footer ) | |
$wp_scripts->add_data( $_handle[0], 'group', 1 ); | |
} | |
$wp_scripts->enqueue( $handle ); | |
} |
This file contains hidden or 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 | |
function wpdocs_theme_name_scripts() { | |
$tag_attrs = array( | |
'async' => 'true', | |
'data-cfasyc' => 'false' | |
); | |
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', $tag_attrs, true ); | |
} | |
add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment