Title: Where to add JavaScript code?
Last modified: December 4, 2022

---

# Where to add JavaScript code?

 *  Resolved [d2earth](https://wordpress.org/support/users/d2earth/)
 * (@d2earth)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/where-to-add-javascript-code/)
 * Regarding your post in the FAQ section:
    “How to open external links in a new
   popup window?”
 * Could you please tell me where I should add the JavaScript code. Thank you.
 * By adding this JavaScript code to your site:
 * jQuery(function ($) {
    $(‘a[data-wpel-link=”external”]’).click(function (e) {//
   open link in popup window window.open($(this).attr(‘href’), ‘_blank’, ‘width=
   800, height=600’);
 *  // stop default and other behaviour
    e.preventDefault(); e.stopImmediatePropagation();});});

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [d2earth](https://wordpress.org/support/users/d2earth/)
 * (@d2earth)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/where-to-add-javascript-code/#post-16260660)
 * Sorted.
    I added an HTML widget to the page I needed this to function on. Then
   it’s important to add <script> and </script> before and after.
 * <script>
    jQuery(function ($) { $(‘a[data-wpel-link=”external”]’).click(function(
   e) { // open link in popup window window.open($(this).attr(‘href’), ‘_blank’,‘
   width=800, height=600’);
 *  // stop default and other behaviour
    e.preventDefault(); e.stopImmediatePropagation();});});
   </script>
 *  Plugin Author [Alexandru Tapuleasa](https://wordpress.org/support/users/talextech/)
 * (@talextech)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/where-to-add-javascript-code/#post-16264562)
 * Hi,
 * Yes, that should work! 🙂
    Happy to hear you managed to set it up.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Where to add JavaScript code?’ is closed to new replies.

 * ![](https://ps.w.org/wp-external-links/assets/icon-256x256.png?rev=2103983)
 * [External Links - nofollow, noopener & new window](https://wordpress.org/plugins/wp-external-links/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-external-links/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-external-links/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-external-links/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-external-links/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-external-links/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Alexandru Tapuleasa](https://wordpress.org/support/users/talextech/)
 * Last activity: [3 years, 6 months ago](https://wordpress.org/support/topic/where-to-add-javascript-code/#post-16264562)
 * Status: resolved