Munshi

If WordPress automatically reverted your changes due to a potential error in the PHP code, you can manually upload the updated functions.php file to your site using SFTP or your hosting’s file manager.

Steps to Manually Upload the Updated functions.php File

1. Access Your Website Files

You can use one of the following methods:

  • SFTP: Use an SFTP client like FileZilla to connect to your website.
  • Hosting File Manager: Log in to your hosting control panel (e.g., cPanel, InfinityFree File Manager) and navigate to your website files.

2. Download and Edit functions.php

  1. Navigate to your theme folder: /wp-content/themes/your-active-theme/
  2. Download the functions.php file to your computer.
  3. Open the file in a text editor like VS Code or Notepad++.

3. Add the Updated Code

Paste the filter code into the file, ensuring no syntax errors are introduced:

function convert_code_to_prismatic($content) {
    // Match <code> elements without a language class
    $content = preg_replace_callback(
        '/<code>(.*?)<\/code>/s',
        function ($matches) {
            return '<code class="language-text">' . esc_html($matches[1]) . '</code>';
        },
        $content
    );
    return $content;
}
add_filter('the_content', 'convert_code_to_prismatic');

Save the file after adding the code.

4. Re-upload functions.php

  1. Upload the modified functions.php file back to your theme folder using SFTP or the hosting file manager.
  2. Replace the existing functions.php file with the updated version.

5. Test Your Site

  • Visit your website to confirm it’s functioning properly.
  • Check the <code> blocks on the front-end to ensure the Prismatic highlighting is applied.

6. Debugging (If Needed)

If you encounter errors after re-uploading the file:

  • Restore the backup of your original functions.php file (always create a backup before editing).
  • Check for syntax errors in the PHP code you added.
  • Use PHP error logs or enable WordPress debugging by adding the following lines to your wp-config.php file:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

Debug logs will be stored in wp-content/debug.log.

Let me know if you need further assistance!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top