General help

Finding the theme's custom CSS in the database

 
Picture of JT Emerson
Finding the theme's custom CSS in the database
 

Guys, I made a HUGE mistake. I set the main block that controls EVERYTHING on my site to "display:none" in the theme's custom CSS field and saved it. Now the block is gone and I can't do ANYTHING on my site. I can't change the CSS back, or even log in. I need to find that CSS in the database and delete that line of code so that I can see the main block of my website again. I am using the IOMAD theme. What table is that custom CSS saved in? Is there another way to fix this? 

Thank you for the help!

-JT

 
Average of ratings: -
Picture of William Lu
Re: Finding the theme's custom CSS in the database
Particularly helpful Moodlers

Hi JT,

Sorry to hear that, and I can feel your desperate–––you posted into the wrong forum. 

I will move your question to General help forum... there more people can help you over there.

I wish you had set 'Allow theme changes in the URL'=YES, then, you can try this:

yourmoodlesite.com/?theme=clean


Good luck.


HTH



 
Average of ratings: -
Picture of Jeff White
Re: Finding the theme's custom CSS in the database
 
  1. Go to developer tools in your browser (F12 key in Google Chrome)
  2. Do a search for "display:none" in the elements tab.
  3. Change display:none to display:inherit.
  4. Your block should show in your browser again
  5. Go find the custom CSS field in the theme.

Note that every time you go to a new page, you are likely going need to do the search again until you remove the CSS setting. 

 
Average of ratings: Useful (2)
Picture of JT Emerson
Re: Finding the theme's custom CSS in the database
 

I actually just figured it out minutes before you replied. I basically did what you suggested.

  1. Viewed page source to find the id of the block
  2. Executed the javaScript in the console to get the element by id and then manipulate the css to display: block. 
  3. Navigated the to the theme options and deleted the bad code that I had written 



var main = document.getElementById("page-content");

main.style.display = "block";


Thanks for the reply though! Great minds think alike (but you probably thought about it for much less time than I did). 


-JT

 
Average of ratings: Useful (1)
Randy Thornton
Re: Finding the theme's custom CSS in the database
Documentation writersParticularly helpful Moodlers

I think that's the best fix, changing the local css in your browser, but just for information:


The answer to the OP is that the custom css is stored in the database in the mdl_config_plugins table.

There will be settings in there for the theme in the plugins column, with a name like "theme_x" where x is the shortname of the theme, e.g. theme_clean, theme_adaptable. The name column you want will have a field called "customcss" and you will see the actual css code in the value column.


I use the same trick as William does above to avoid such issues: I ALWAYS turn on session level themes in any Moodle site I work on, just to be able to troubleshoot theme issues.



 
Average of ratings: -
on the Great Wall
Re: Finding the theme's custom CSS in the database
Particularly helpful Moodlers

Randy, 

Know this thread is a year old but your advice so far is one of best I have come to tracking down where all of this extra code goes. 

I have been able to use MyphpAdmin and find the table.. thanks .. 


But the Question I have got and it may be for the themer's to answer. its a Noobs questions so be gentle... smile

Why is it that I can see a custom.css file in with the moodle-theme_adaptable/style/ directory ?

With none of my customs css being written to it?

Where with in the theme is the custom css being written to?

or is it that it only ends up in the database table?


Is it that we are to create a child theme under the main theme to really change this to where we might want to be?

Rick Jerz does put it well in his answer and I kinda get the idea there after looking at his presentation..

https://moodle.org/mod/forum/discuss.php?d=361053#p1456096





 
Average of ratings: -
Randy Thornton
Re: Finding the theme's custom CSS in the database
Documentation writersParticularly helpful Moodlers


Daniell,

Right, custom.css seems a logical place to put things, but if you think about it, your web server never normally writes to files in the /moodle directory except during installs & upgrades. If it needs to change files on the fly, it needs to use /moodledata. For example, custom language strings, custom sql reports, etc., go there.

The custom.css file is just the standard name of the main css file for a theme: even Clean and More have that file in the style directory. That file is created by the theme developer and will never changed unless you upgrade the theme. 

I would suppose that it is called custom because it is a customization of base, Bootstrapbase.

If you make a dependent theme, you will always have your own /style directory with a custom.css file in it to control your theme's customizations which override styles from base. Look at the files for Clean or More for examples.

What a user puts in the custom CSS box for a theme via the admin interface is stored in the database not in that file.

Now, things are different for Boost and themes which are now using scss. I don't know much about them at all but the structures are quite different which makes sense since scss can @import things like crazy and is a different way of working.


Randy

 
Average of ratings: -
on the Great Wall
Re: Finding the theme's custom CSS in the database
Particularly helpful Moodlers

Randy, 

Yes, big thanks for the details. 

Its been bugging me for ages now and where it all fits together as I wanted to keep a tidy code file going off server.  

Now I know where it is I can just keep one and add to any upgrades I need to do.. Plus this now allows me to be a bit more adventurous with the JavaScript add-ins as well. 

Just perfected a Lightbox (Modal Image Gallery) that looks great. 

Will do a write up in my running blog on it as I have seen Mary allude to Modals becoming more of the norm in to the future. 


 
Average of ratings: -