<div dir="ltr">What do you mean by "put before" your enqueued scripts? Can you give a use-case/example?<div><br></div><div style>If you need to *print* a script before other enqueued scripts, you can do several things. Here are a couple:</div>
<div style><br></div><div style>1. Make the script a *dependency* of the later scripts</div><div style>2. Hook the script into wp_head, at priority 0.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jan 22, 2013 at 1:34 PM, Abhik Biswas <span dir="ltr"><<a href="mailto:abhik@itsabhik.com" target="_blank">abhik@itsabhik.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div><div>Okay,<br></div>So, what if I need to put something *before* my enqueued scripts, what should I use?<br>
<br></div>Is this the right way?<br><br></div>function my_scripts() { ?><br>
<script type="text/javascript"><br>........<br></div></scripts><br><br></div><?php }<br></div>add_action ('wp_enqueue_scripts', 'my_scripts', 5 );<br><br></div><br><br><br><br>function my_enqueued_scripts() {<br>
<br></div> wp_enqueue_script ('myscript', ...... myotherscript.js....., '');<br><br>}<br>add_action ('wp_enqueue_scripts', 'my_enqueued_script', );<br></div><div class="HOEnZb"><div class="h5">
<div class="gmail_extra"><br><br>
<div class="gmail_quote">On Tue, Jan 22, 2013 at 11:56 PM, Otto <span dir="ltr"><<a href="mailto:otto@ottodestruct.com" target="_blank">otto@ottodestruct.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The question itself is slightly confusing, because it kinda depends on<br>
the purpose...<br>
<br>
For the front-end of the site, the wp_print_scripts action is actually<br>
executed from the wp_print_head_scripts() function.<br>
<br>
The wp_print_head_scripts() function is actually hooked to the wp_head<br>
action, like so:<br>
add_action( 'wp_head', 'wp_print_head_scripts', 9 );<br>
<br>
Same goes for wp_enqueue_scripts. The wp_enqueue_scripts action is in<br>
the wp_enqueue_scripts() function which is called like so:<br>
add_action( 'wp_head', 'wp_enqueue_scripts', 1 );<br>
<br>
So the answer is different depending on whether you consider the<br>
action to have occurred when the action is called or when the action<br>
has returned.<br>
<br>
The long and the short of it is that both enqueuing and printing of<br>
scripts happen inside the wp_head() call. So the question of ordering<br>
isn't something that external code really needs to consider. Instead,<br>
you need to know that you should add scripts on wp_enqueue_scripts,<br>
and remove scripts on wp_print_scripts (as this is the last possible<br>
moment to remove them before they get printed to the output).<br>
<span><font color="#888888"><br>
-Otto<br>
</font></span><div><div><br>
<br>
On Tue, Jan 22, 2013 at 12:16 PM, Michael Fields <<a href="mailto:michael@mfields.org" target="_blank">michael@mfields.org</a>> wrote:<br>
> Here's a simple way to test this:<br>
><br>
> <?php<br>
> function mfields_test_some_hooks() {<br>
> static $i = 1;<br>
> var_dump( $i . ' - ' . current_filter() );<br>
><br>
> $i++;<br>
> }<br>
><br>
> add_action( 'wp_head', 'mfields_test_some_hooks' );<br>
> add_action( 'wp_print_scripts', 'mfields_test_some_hooks' );<br>
> add_action( 'wp_enqueue_scripts', 'mfields_test_some_hooks' );<br>
> ?><br>
><br>
> I get the following order:<br>
><br>
> 1 - wp_enqueue_scripts<br>
> 2 - wp_print_scripts<br>
> 3 - wp_head<br>
> _______________________________________________<br>
> theme-reviewers mailing list<br>
> <a href="mailto:theme-reviewers@lists.wordpress.org" target="_blank">theme-reviewers@lists.wordpress.org</a><br>
> <a href="http://lists.wordpress.org/mailman/listinfo/theme-reviewers" target="_blank">http://lists.wordpress.org/mailman/listinfo/theme-reviewers</a><br>
_______________________________________________<br>
theme-reviewers mailing list<br>
<a href="mailto:theme-reviewers@lists.wordpress.org" target="_blank">theme-reviewers@lists.wordpress.org</a><br>
<a href="http://lists.wordpress.org/mailman/listinfo/theme-reviewers" target="_blank">http://lists.wordpress.org/mailman/listinfo/theme-reviewers</a><br>
</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
theme-reviewers mailing list<br>
<a href="mailto:theme-reviewers@lists.wordpress.org">theme-reviewers@lists.wordpress.org</a><br>
<a href="http://lists.wordpress.org/mailman/listinfo/theme-reviewers" target="_blank">http://lists.wordpress.org/mailman/listinfo/theme-reviewers</a><br>
<br></blockquote></div><br></div>