• Resolved Deleted Account

    (@myst5243)


    I want to add inline Javascript on footer of my wordpress site. I know we can add inline Javascript using wp_add_inline_script. From my understanding from Codex tutorial, we have to register and enqueue scripts and then using wp_add_inline_script.

    Let say I:

    1. Register ScriptA.js using wp_register_script.
    2. Enqueue ScriptA.js using wp_enqueue_script.
    3. Add inline ScriptB.js using wp_add_inline_script with handle ScriptA.js.

    My Question:

    1. As far as I can remember, Adblock Plus (Web browser ext) or similar can block external .js. If my ScriptA.js being blocked by Adblock Plus, will my ScriptB.js loaded?
    2. IF it is blocked, is there any other proper way I can add inline Javascripts? The only I can think is simply print (echo) it using wp_footer hook.

    Reason using inline Javascripts: To prevent Adblock user from blocking my Ads script. Because Adblock Plus cannot block inline script as said by their Dev.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    The inline script is still output even if the enqueued file request is blocked. AFAIK anyway, not verified, but I’m pretty sure this is the case. The inline output cannot know the enqueued request was blocked, the block is external to the server. Of course, the added inline cannot be dependent on the blocked enqueued script if it is to work correctly. Your ad content would need to be part of the inline script, any external requests can still be blocked.

    While AdBlock cannot block inline script, it can remove specific DOM elements. The key is to avoid having any consistent identifiers in your ad elements.

    Thread Starter Deleted Account

    (@myst5243)

    Hello @bcworkz,

    Thank you for your answer. I tried to block my own external .js and it seems my inline js still output successfully. Although I’m not sure either I test it right way or not.

    While AdBlock cannot block inline script, it can remove specific DOM elements. The key is to avoid having any consistent identifiers in your ad elements.

    Thank you for your advice/suggestion. This is what I need at my inline js.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add Inline Javascript’ is closed to new replies.