WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why does the jquery below not fire? Its going to the "else" every time.

if ( is_admin() && $pagenow == 'theme-install.php' && $_GET['tab']=="upload"){
    add_action('admin_print_scripts', 'theme_upgrade_alert');
    function theme_upgrade_alert(){
        echo '
        <script type="text/javascript">
        if(typeof jQuery!="undefined"){
            alert("If you are attempting to upgrade the current theme, you must do it via theme options.");
share|improve this question
Please remember, jQuery is loaded in the admin by default ... – EAMann Feb 9 '12 at 16:32
Not sure where you're calling this from, but $pagenow is in the topmost scope; if this is inside a function or include, did you remember to global $pagenow; before this block? – goldenapples Feb 9 '12 at 17:02
up vote 6 down vote accepted

First, check for syntax errors. The syntax highlighting seems to indicate that you have syntax errors.

Second, don't wrap your add_action() calls inside conditionals; rather, wrap your callback function content inside the conditionals, e.g.:

function theme_upgrade_alernt() {
    if ( is_admin() && $pagenow == 'theme-install.php' && $_GET['tab']=="upload"){
        // CODE GOES HERE
    } else {
add_action('admin_print_scripts', 'theme_upgrade_alert');

I would also recommend enqueueing your scripts at admin_enqueue_scripts, rather than admin_print_scripts.

share|improve this answer

jquery is always loaded in the admin.

you can see it in the source:

<script type='text/javascript' src='http://localhost/multi/wp-admin/load-scripts.php?c=1&amp;load=jquery,utils&amp;ver=3.4-alpha-19704'></script>

also you need to put your conditional logic inside your function. and maybe you can use


instead of admin_print_scripts so it will only fire on that page.

share|improve this answer

You're enqueuing jQuery, but then just echo'ing out your script. At the time your script runs on the page, jQuery hasn't loaded yet. You enqueued it, but you haven't waited for that enqueue to cause an action on the page output.

Move your script output down to later in the page (like into the footer), or wrap it in something like a jQuery(document).ready() wrapper, so that it runs after the page has finished rendering.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.