header.php erased upon trying to edit it in theme editor

  • Unknown's avatar

    Hi there,

    Yesterday I was trying to edit a line in header.php within the theme editor and got the following error

    It was not possible to communicate with the site to check for fatal errors, so the PHP change has been reversed. You will have to upload the change to your PHP file by other means, such as using SFTP.

    Upon going to my site i realized that all the css was stripped out so I went back to the theme editor to check what was wrong as header.php was the only thing I had tried to edit before this happened. I open it, and it’s completely blank, gone.
    Fortunately I had backed up the file, before attempting to edit it, however when I pasted the code in and tried to save I kept getting the same error as above.

    Doing some searches on stack overflow and other sites I saw that newer versions of WP do not allow you to edit header.php from the front end/theme editor (despite it still being available for editing in the theme editor), as is clear by the error it throws, but it doesn’t explain why it just blanked out the file.

    I also researched through several sources that the easiest/best way to solve this would be to manually edit header.php in the WP-content directory.
    However, I believe this assumes I have WP downloaded in my computer , which is not the case as I was only working through the browser.
    Someone please correct me if I’m wrong and I can still access this directory.

    Or perhaps there is a different solution to this that I’m not yet aware of..?

    P.S. I’ve also tried multiple plugins that allow you to edit the head file however so far all of them only accept static content (html, css, js), and since WP is served up dynamically the head file also need php to render it. so none have worked to re-enter the code.

  • Unknown's avatar

    Case 1

    Case 2

    Case 3

    Here are a few other similar cases

    Header.php file is in the theme directory, find out what’s your theme, open your themes zip file(when you bought theme, you got .zip file), extract header.php file and upload.

    Any idea how i could do this? Im unable to paste it in through theme editor

  • I don’t see any WordPress.com sites under your account here.

    What is the URL of the site with the problem?

    NOTE: We can only assist with websites hosted here at WordPress.com. If you’re using the WordPress software, but hosted elsewhere, you will need to reach out to your hosting provider or the WordPress.org community for guidance: https://wordpress.org/support/

  • The topic ‘header.php erased upon trying to edit it in theme editor’ is closed to new replies.