Tip: Know where to put your code so it does what you want

There are different places you can put code in Wix Code and it’s important to know the difference so you put the right code in the right place.

For this tip we’re going to focus on code that runs in your visitor’s browser. There are three places where you can add code to run in the browser:

  1. The Page tab of the Code Panel

  2. The Site tab of the Code Panel

  3. The Public section of the Site Structure sidebar
    Let’s take them one at a time.
    Page tab - This is where you put code that only affects the page it’s on. You’ll use this tab for code that controls the elements that appear only on one page.
    Site tab - This is where you put code that runs on every page in your site. You’ll use this tab for code that controls elements that are set to appear on all pages.
    Public section - This is where you put JavaScript files that contain code you want to use on any page in your site. You can also use code from one Public file in another one.

You can learn about the Page and Site tabs here . The difference between code in Public files and the Site tab is that code in the Site tab runs automatically on all your site’s pages, but code in Public files runs only where you import that code. This is important because if you don’t need code to run on every page it’s probably better if it doesn’t, since it could affect your site’s performance. In that case it’s better to put the code in a Public file and just call it when you need it.

You can learn about how to import code from Public files here .

One last point. Any code that you place in any of the three locations we’ve discussed runs in the visitor’s browser and could be viewed by them. This could be a security issue, and for this reason it’s important to think about which code you put there. For example, you may not want to put code that contains any private or sensitive information in these locations. You can learn more about security issues and code visibility here .

Of course, you can learn all about Wix Code here .