[wp-trac] [WordPress Trac] #25277: WP_scripts does not allow to add data after the enque has been added to HTML
WordPress Trac
noreply at wordpress.org
Wed Sep 11 09:25:52 UTC 2013
#25277: WP_scripts does not allow to add data after the enque has been added to
HTML
-----------------------------+-----------------------------
Reporter: hakre | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 3.6
Severity: normal | Keywords: has-patch
-----------------------------+-----------------------------
For example if a template part makes use of a jQuery plugin that needs
jQuery but additionally some javascript code to initialize the plugin
which is not inside a js file, the data "data" can not be used to set that
initialization code for the enqueued script becuse it would be put before
the resource is loaded:
Example Code:
{{{
$wp_scripts->add("jquery.webticker", get_stylesheet_directory_uri() .
"/js/jquery.webticker.js", array("jquery"));
$wp_scripts->add_data("jquery.webticker", "data",
"jQuery('#webticker').webTicker();");
$wp_scripts->enqueue("jquery.webticker");
}}}
Example Output:
{{{
<script type='text/javascript'>
/* <![CDATA[ */
jQuery('#webticker').webTicker();
/* ]]> */
</script>
<script type='text/javascript' src='http://example.com/wp-
content/themes/example/js/jquery.webticker.js?ver=3.6'></script>
}}}
This feature request suggests to allow an additional key to be used
instead of "data" (here exemplary "data-after") to place script contents
*after* the enqueued script:
Example Code (after patch):
{{{
$wp_scripts->add("jquery.webticker", get_stylesheet_directory_uri() .
"/js/jquery.webticker.js", array("jquery"));
$wp_scripts->add_data("jquery.webticker", "data-after",
"jQuery('#webticker').webTicker();");
############
$wp_scripts->enqueue("jquery.webticker");
}}}
Example Output (after patch):
{{{
<script type='text/javascript' src='http://example.com/wp-
content/themes/example/js/jquery.webticker.js?ver=3.6'></script>
<script type='text/javascript'>
/* <![CDATA[ */
jQuery('#webticker').webTicker();
/* ]]> */
</script>
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/25277>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list