- This topic has 7 replies, 2 voices, and was last updated 4 years, 5 months ago by
Leo.
-
AuthorPosts
-
March 20, 2021 at 2:22 pm #1703279
Den
Hi team,
Thanks for your 24×7 support.
The thing is, I’m getting an error while saving a code on my functions.php
THE CODE
function myFunction() { var element = document.body; element.classList.toggle("dark-mode"); }
THE ERROR THAT I AM GETTING
Your PHP code changes were rolled back due to an error on line 84 of file wp-content/themes/generatepress/functions.php. Please fix and try saving again. syntax error, unexpected 'var' (T_VAR)
What’s the issue? I didn’t quite get that. Can you please figure out how do I make it worked?
BTW, this is what i wanna achieve – https://www.w3schools.com/howto/howto_js_toggle_dark_mode.asp
March 20, 2021 at 2:26 pm #1703284Leo
StaffCustomer SupportHi there,
Are you editing the theme’s
function.php
?It’s never a good idea to do this as your code will be erased during updates.
Can you revert the file to the original state first?
https://github.com/tomusborne/generatepress/blob/master/functions.phpThis is something that should be done in the function.php file of a child theme:
https://docs.generatepress.com/article/using-child-theme/March 20, 2021 at 2:28 pm #1703287Den
Hi leo,
No, I am editing the Child Theme’s function.php
(not the parent theme) 🙂
March 20, 2021 at 2:32 pm #1703288Leo
StaffCustomer SupportHmm the error you are showing me above is indicating that the error is in the parent theme’s
function.php
:
wp-content/themes/generatepress/functions.php
And there is definitely no error in line 84:
https://github.com/tomusborne/generatepress/blob/master/functions.php#L84Can you make sure the parent theme’s function.php matches the file I linked?
Or you can reinstalling the theme.
March 20, 2021 at 2:40 pm #1703293Den
Nope, nothing’s wrong with my parent theme’s function.php (I’ve just checked it)
It’s just when I try to add this code…
function myFunction() { var element = document.body; element.classList.toggle("dark-mode"); }
– on my website, it just won’t let me save that changes because there’s some error in
var element = document.body;
that I’m getting.See here – https://ibb.co/dbFkCpm
(now it’s on the line 49)
——————————————————
I just want to enable “Toggle Dark Mode” on my website.
and to do this, as per w3schools.com,
I have to add a CSS
body { padding: 25px; background-color: white; color: black; font-size: 25px; } .dark-mode { background-color: black; color: white; }
and a javascript
function myFunction() { var element = document.body; element.classList.toggle("dark-mode"); }
to enable this function.
March 20, 2021 at 2:47 pm #1703297Leo
StaffCustomer SupportWe can’t help with custom functions here as it’s not part of the theme:
https://generatepress.com/what-support-includes/But looks like you might have extra
endif;
at line 53?March 20, 2021 at 2:48 pm #1703299Den
Alright, not an issue
Thanks 🙂
March 20, 2021 at 2:54 pm #1703302Leo
StaffCustomer SupportNo problem 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.