[theme-reviewers] Which one get processed first? print_scripts or enqueue_scripts?

Abhik Biswas abhik at itsabhik.com
Tue Jan 22 18:34:28 UTC 2013


Okay,
So, what if I need to put something *before* my enqueued scripts, what
should I use?

Is this the right way?

function my_scripts() { ?>
<script type="text/javascript">
........
</scripts>

<?php }
add_action ('wp_enqueue_scripts', 'my_scripts', 5 );





function my_enqueued_scripts() {

 wp_enqueue_script ('myscript', ...... myotherscript.js....., '');

}
add_action ('wp_enqueue_scripts', 'my_enqueued_script', );


On Tue, Jan 22, 2013 at 11:56 PM, Otto <otto at ottodestruct.com> wrote:

> The question itself is slightly confusing, because it kinda depends on
> the purpose...
>
> For the front-end of the site, the wp_print_scripts action is actually
> executed from the wp_print_head_scripts() function.
>
> The wp_print_head_scripts() function is actually hooked to the wp_head
> action, like so:
> add_action( 'wp_head', 'wp_print_head_scripts', 9 );
>
> Same goes for wp_enqueue_scripts. The wp_enqueue_scripts action is in
> the wp_enqueue_scripts() function which is called like so:
> add_action( 'wp_head', 'wp_enqueue_scripts', 1 );
>
> So the answer is different depending on whether you consider the
> action to have occurred when the action is called or when the action
> has returned.
>
> The long and the short of it is that both enqueuing and printing of
> scripts happen inside the wp_head() call. So the question of ordering
> isn't something that external code really needs to consider. Instead,
> you need to know that you should add scripts on wp_enqueue_scripts,
> and remove scripts on wp_print_scripts (as this is the last possible
> moment to remove them before they get printed to the output).
>
> -Otto
>
>
> On Tue, Jan 22, 2013 at 12:16 PM, Michael Fields <michael at mfields.org>
> wrote:
> > Here's a simple way to test this:
> >
> > <?php
> > function mfields_test_some_hooks() {
> >         static $i = 1;
> >         var_dump( $i . ' - ' . current_filter() );
> >
> >         $i++;
> > }
> >
> > add_action( 'wp_head',            'mfields_test_some_hooks' );
> > add_action( 'wp_print_scripts',   'mfields_test_some_hooks' );
> > add_action( 'wp_enqueue_scripts', 'mfields_test_some_hooks' );
> > ?>
> >
> > I get the following order:
> >
> > 1 - wp_enqueue_scripts
> > 2 - wp_print_scripts
> > 3 - wp_head
> > _______________________________________________
> > theme-reviewers mailing list
> > theme-reviewers at lists.wordpress.org
> > http://lists.wordpress.org/mailman/listinfo/theme-reviewers
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20130123/a08ae27a/attachment.htm>


More information about the theme-reviewers mailing list