Specifying javascript/html for individual pages
-
Hi,
I've read the instructions here : http://laytheme.com/documentation.html#custom-javascript
I'm working on a site with heavy Javascript and CSS customization, so declaring the CSS and Javascript globally is really slowing down everything.
Ideally it would be best to only include the CSS/JS on the relevant page, but the +HTML option seems to not work for CSS or JS
I would like to specify some CSS and JS for each page and not have it load globally.
The format you suggest is :
<script>
window.laytheme.on("newpageshown", function(layoutObj, type, obj){
if(type == "project" && obj.id == 1){
...
}
});
</script>Is there a way to
- use the +HTML to include page specific CSS/JS
- if not, a more direct formatting (without using if statements)
something like what we use for page specific CSS
.slug-home .class {}I've tried to send the slug as a variable, but doesn't work.
Thanks for the help as usual,
Daniel -
Dear @dani
it works.
Give it a test with an alert function:Maybe your code is causing a problem.
Best!
Marius
-
Hi Marius,
Thanks. The code I'm using works fine from 'Custom CSS & HTML'.
When I copy/paste the exact code from Custom CSS & HTML' and put it directly on the page using +HTML it doesn't work anymore.
The test you recommend works for me too, but the added code (using +HTML) isn't in the source. (search for your name in the source, nothing comes up)...
http://visuel.org/test
view-source:http://visuel.org/testDaniel
-
there is definitely a bug somewhere
when i visit http://visuel.org/clouds from this link it works fine (except when screen size is changed or console comes up... it disappears)
but when the clouds page is accessed from the main page http://visuel.org (link at bottom of page), nothing shows up.
i don't see the CSS or JS in the source either...
please advise,
thanks! -
Dear @dani
try the plain jQuery like this:
<script> console.log("AAA"); </script>
Let us know if this works for you.
Best!
Marius
-
hi marius,
it's the same with or without :
window.laytheme.on("newpageshown", function(layoutObj, type, obj){the new page only reads the js when accessed directly through the browser url bar, not linked from another page on the site (home page). That is the issue.
I can send my login if you could have a closer look.
Thank you,
Daniel -
Dear @dani
have a look on my test page:
http://www.laytheme.mariusjopen.com/javascriptThis is the code which gets triggered
<script> alert("TEST"); jQuery( "body" ).addClass( "TEST" ); </script>
The function gets triggered if you open the page with URL or when you open it via another page.
Best!
Marius
Before you post:
- When using a WordPress Cache plugin, disable it or clear your cache.
- Update Lay Theme and all Lay Theme Addons
- Disable all Plugins
- Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"
This often solves issues you might run into
When you post:
- Post a link to where the problem is
- Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
- If the problem is difficult to explain, post screenshots / link to a video to explain it