• Resolved Salvatore Noschese

    (@salvatorenoschese)


    hi, I need to add a stats code for all users (guest or logged) except for myself (admin).

    tried this, but seems to not work as expected.

    any help?

    add_action('wp_footer', 'insert_js_into_footer');
    function insert_js_into_footer() {
        if ( ! current_user_can('administrator')) {
            ?>
            <!-- my code here -->
            <?php
        }
    }
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • tried this, but seems to not work as expected.

    I copied and pasted your code, and it works for me as expected.

    In what way is it working that’s not expected?

    (The only thing I can think of why the code may not be working at all is if your theme is not calling wp_footer.)

    Thread Starter Salvatore Noschese

    (@salvatorenoschese)

    work so good (but just for all) with simply:

    add_action('wp_footer', 'insert_js_into_footer');
    function insert_js_into_footer() {
        #if ( ! current_user_can('administrator')) {
            ?>
            <!-- my code -->
            <?php
        #}
    }
    

    without # simply I can’t see (both for guest in private browser and by admin).

    anytime flush litespeed cache but issue remain.

    threadi

    (@threadi)

    It works fine for me – but without any cache plugin. I suspect that this is the problem for you. Or perhaps another plugin that is interfering with the check. Try deactivating it to find the culprit.

    Thread Starter Salvatore Noschese

    (@salvatorenoschese)

    ty. after some test, I think is an issue with incognito mode here in Firefox mobile. I see code like from logged user (I search for login widget and I seen my name also if apparently I’m absolutely not logged in). Maybe an issue with view source plugin. Tomorrow I check from desktop. Ty

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘add code for all except admin’ is closed to new replies.