How to Fix a Broken WordPress Theme or Plugin

Fix a Broken WordPress Theme or Plugin

Have you ever got frustrated with a broken theme or plugin that certain stylings or functions are broken or messed up? In this blog post, I’ll try to address some possible solutions to fix a broken WordPress theme or plugin.

The very obvious solution is to contact the theme or plugin developer and they will fix everything for you! The challenge is that most these developers might not even get back to you for weeks or months. You are now hooped because you need the fix asap. I also the learned one of the hard ways – hacking the theme by modifying the script and CSS files. However, this might not be the best solution since you can no longer update the theme without overwriting all your changes. So what should you do?

Although I am a professional designer developer with over 15 years of experience, I don’t intend my readers for this blog or any of my blogs to know too much programming. One of the best solutions is to create your own plugin to fix the problem!  Wow, that sounds way too complicated. Actually, it is very simple. The plugin I am creating here is very simple and requires some basic knowledge of Linux and little programming.

Creating a WordPress Plugin

If you are using apache2, you can create your first plugin with these steps:

ssh username@domainname.com
cd /var/www/html/wp-content/plugins/
mkdir myplugin
cd myplugin
touch myplugin.php
mkdir css
touch css/style.css
mkdir js
touch js/script.js
nano myplugin.php

You have just created the folder structure for a standard PHP plugin. Go ahead and activate the plugin inside the Plugins settings page.

Add and save the following lines to myplugin.php:

<?php
   /*
   Plugin Name: My Plugin
   Description: A plugin for wordpress customizations
   Version: 1.0
   Author: VantageWork Solutions Inc.
   Author URI: https://webdesign.vantagework.com
   */

function vw_date() {
    return date( 'M j, Y' );
}
add_shortcode( 'vw_date', 'vw_date' );

add_action('init', 'register_script');
function register_script() {
    wp_register_style( 'vw_style', plugins_url('/css/style.css', __FILE__), false, '1.0.0', 'all');
    /* wp_enqueue_script( 'vw_script', plugins_url('/js/script.js', __FILE__) ); */
}

add_action('wp_enqueue_scripts', 'enqueue_scripts', 1000);
function enqueue_scripts(){
   wp_enqueue_style( 'vw_style' );
   /* wp_enqueue_script('vw_script' ); */
}
?>

If you want to add some custom strings or outputs to your theme, you can just use the add_shortcode function similar to line 13 above. Otherwise, the last two functions look for the style.css, where you can make your styling changes. If you need to add your own javascript, you can uncomment line 18 and 24 and call the wp_enqueue_script functions.

Add your CSS code to style.css

body { color: #03c4eb; }

You have just changed the style of your body text to light blue! You can make any adjustments you need inside this file without dirtying what the vendor gives you. If there’s an update, you can download the latest theme or plugin without breaking your changes, assuming that the vendors haven’t changed the name of the ids or classes.

Add your JAVASCRIPT code to script.js

alert("Hello World!");

Great! You have just created your first plugin, which can be used to fix a broken WordPress theme or plugin. Make you activate the plugins just like any other plugins you installed online. If you like this post, please comment on it and I will make more of these how-to blogs in the future. You can now add your changes in the plugin and fix or modify your broken theme or plugin.

Please visit our homepage VantageWork Solutions Inc. to learn more about us. We are dedicated to helping small and medium businesses in web design, SEO, and marketing automation.

Leave a Reply

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