Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
1.2k views
in Q2A Core by

How can i add text/javascript to all sites/subsites?


I have to add it to every page Q&A:

<script type="text/javascript" src="whcookies.js"></script>

1 Answer

+2 votes
by
selected by
 
Best answer
Admin ---> Layout ---> "custom HTML at <your position>"
by
I did as you wrote but it does not work
by
What do you mean with "does not work" ?
If you do "view source" on your browser you do not see the script ?
by
Yes, i don't see my script. I added everything as it should be.
I added this script:
<script type="text/javascript" src="whcookies.js"></script>
to my qa-theme.php. I see my script only on first page (main page). I need to see this script on all of my subpages.
by
Have you tried to add it on your admin panel , as I wrote to you above ?
by
Yes I tried do that. That did not help. Nothing happened
by
"Nothing happened" ? Can you explain what do you mean exactly ?
Have you done "view source" ?
You should see the above code included inside the pages.
That type of inclusion works.
I use it on my site and I can see that the code is included inside the page.
by
But if with "nothing happened" you mean that your js does not work, verify that the SRC attribuite contains the correct value
by
View source, what u mean? Really, my .js working.
by
Ohhh, these source...
I have my .js there (on main page and all subpages). I don't know what is wrong...
by
So your code has been successfully added to your pages ... (your question).
What were you expecting to see ?
by
Join to my website:
http://askingleague.ct8.pl

At top u can see note "Ta strona używa ciasteczek (cookies), dzięki którym nasz serwis może działać lepiej. Dowiedz się więcej"

Please enter deeper into the site. Click for example tags, users or something.
Information which you see on the main page at the top - disappeared! ("Ta strona używa ciasteczek (cookies), dzięki którym nasz serwis może działać lepiej. Dowiedz się więcej")
by
Ok,
below my comments :

1) I notice that the statement :
<script type="text/javascript" src="whcookies.js"></script>
is included 3 times in every page.
It should be added only 1 time.
I think you're adding it (2 times) from an advanced theme head_script function, aren't you ?
(1 time is added as I told you above)
Include it only 1 time.

2) I see that you have placed the js in your doc root.
Include it using this syntax :

<script type="text/javascript" src="/whcookies.js"></script>

it should work with the URL scheme that you have adopted ( "/index.php/123/why-do-birds-sing")
by
My god...! One stupid tag "/".
Now everything works as it should.
Thank you for your willingness, wasted time and help. Really!
...