HTML Head Customization broke my forums


(Jonah Aragon) #1

I added some code to the HTML header and it broke my forums, is there a way to remove it via SSH or something? I can access the Admin panel but I can’t remove the code because the Save button doesn’t work, none of the buttons seem to on my forums, which is the problem.

Edit: Running the latest version as of now (beta6)


(Régis Hanol) #2

If you can reach the admin section, you should force reload the page (CTRL+F5) in order to be able to remove the code and click the save button.


(Jonah Aragon) #3

Unfortunately, it seems I’ve left the Admin panel after adding the code, not knowing it broke most of the save and post buttons. If I click Save it stays on Saving, but doesn’t save.


(Régis Hanol) #4

What code did you put in the HTML header? What’s the error in the Javascript console of your browser?


(Jonah Aragon) #5

I put this in my header to test something out (not that smart I see):

<script type="text/javascript">
  WebFontConfig = {
    google: { families: [ 'Montserrat:400,700:latin' ] }
  };
  (function() {
    var wf = document.createElement('script');
    wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
      '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
    wf.type = 'text/javascript';
    wf.async = 'true';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(wf, s);
  })(); </script>
  <link href='https://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
<style>
.loader {
	position: fixed;
	left: 0;
	top: 0;
	width: 100%;
	height: 100%;
	z-index: 9999;
	background: url('http://smallenvelop.com/wp-content/uploads/2014/08/Preloader_7.gif') 50% 50% no-repeat rgb(249,249,249);
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(window).load(function() {
	$(".loader").fadeOut("slow");
})
</script>
<div class="loader"></div>

And I get this in the console:

Uncaught TypeError: undefined is not a function
Failed to load resource: net::ERR_CACHE_MISS

But I can’t do anything about it because I can’t edit the HTML Head in Discourse, and don’t know where that would be saved to be edited in SSH, which is what I really need to know.


(Jonah Aragon) #6

Here, if I delete everything in that box and press save the button stays on Saving... indefinitely, and I’ve restarted my server and internet connection, and it’s not a connection issue, it’s just messed up. I need a way to change that header code manually.


(Jeff Atwood) #7

@techapj perhaps this needs to be in the advanced tips howto.


(Kane York) #8

I just noticed that you’re loading another jQuery - perhaps having two is creating a conflict?


(Jonah Aragon) #9

Yes, I believe that may be the main problem, but I can’t do anything about it at this point. I need these forums back up ASAP so any advice/guides would be great.


(Dean Taylor) #10

I claim no responsibility for your use of these instructions - but this is what I would do:

  1. Sign into your instance.
  2. Get a command shell in your apps docker instance
    cd /var/discourse/
    ./launcher enter app
  3. Open a PostgreSQL interactive terminal
    sudo -u postgres psql postgres
  4. Change Database to discourse
    \c discourse
  5. Update the HTML head setting to comment out everything in it - execute this SQL statement:
    update site_texts SET value = concat('<!-- ', value, ' -->') where text_type = 'head';
  6. Quit PostgreSQL interactive terminal
    \q

Then check and see if the site is working.

EDIT: alternatively you could use this SQL command to set HTML head to empty:
update site_texts SET value = '' where text_type = 'head';


Bad JS customizations - how to fix in the backend?
(Jonah Aragon) #11

I’ll try that and see, thanks :slight_smile:


(Jonah Aragon) #12

Wow. That worked like a charm, thanks @DeanMarkTaylor :smiley: Everything seems to be working now I guess, this would be a good tutorial maybe for noobs like me who mess everything up :laughing:

Thanks again!


(kinjo) #13

i also having problem


(Mittineague) #14

Hi kinjo welcome to the forum

AFAIK the site_texts table is no more.

I recently broke my localhost during some experimenting.

I had put the problem code in the </head> pane.

I needed to run this in the db CLI

UPDATE site_customizations 
SET head_tag = "", head_tag_baked = "" 

and then
./launcher rebuild app

Depending on where you put the problem code you may need to UPDATE different fields. eg .

site_customizations
id    serial    primary key 
name    varchar(255) 
stylesheet    text    null 
header    text    null 
user_id    integer    fkey users 
enabled    boolean 
key    varchar(255) 
created_at    timestamp 
updated_at    timestamp 
stylesheet_baked    text 
mobile_stylesheet    text    null 
mobile_header    text    null 
mobile_stylesheet_baked    text    null 
footer    text    null 
mobile_footer    text    null 
head_tag    text    null 
body_tag    text    null 
top    text    null 
mobile_top    text    null 
embedded_css    text    null 
embedded_css_baked    text    null 
head_tag_baked    text    null 
body_tag_baked    text    null 
header_baked    text    null 
mobile_header_baked    text    null 
footer_baked    text    null 
mobile_footer_baked    text    null

(Chris Birch) #16

Hi,

I am also having this problem and the solutions above don’t seem to work. Does anyone have an updated solution to this issue?


(Michael - DiscourseHosting.com) #17

Append /safe-mode to your hostname, i.e. go to https://yourforum.yourdomain.com/safe-mode

Then you can opt to disable the current theme.


(Chris Birch) #18

This doesn’t work :cry:

The javascript is in the head and is redirecting from the forum to a holding page that was intended to only show whilst some changes were made. Can’t access the admin dashboard to remove the javascript and /safe-mode still redirects away from the forum.


(Michael - DiscourseHosting.com) #19

How about:

  • Disable javascript in your browser
  • Go to /safe-mode
  • Disable theme
  • Enable javascript
  • go to Admin
  • fix theme

(Chris Birch) #20

That worked! Life saver, thank you so much!


(Joshua Rosenfeld) #21

For future reference, adding the safe mode url query itself should bypass even javascript, I used this once before.

https://forum.example.com/latest?safe_mode=no_custom