How to modify any existing WordPress site CORRECTLY!
Almost in 99% cases I’ve met, WordPress website holders, who want to modify their chosen theme/template or plugin functionality, they (or their programmers) do that in following way:
- Modify and hardcode the original theme files, inject their codes and creating some extra files in that theme directory
- In their personal notes (or somewhere in the damn), they save the list of modification – which files they have modified and what they did and etc.
- The most horrible glitch is, that very very soon, you will see the WordPress notes, that your Theme/WordPress/Plugins has a new release and you should upgrade. However, the hysterical WARNING comes into your mind – no, you MUST NOT do that, because all your theme modifications will be spoiled and your site will mess-up… EXCELLENT, right?
- The next horrible thing what a “developer” might do, is that he DISABLES (OUH!!) wordpress notifications, that tells you about updates…
- Well, if the above steps are familiar with you – then it’s time to think and tell yourself- that it’s time to change your “skills” – or stay forever as an unprofessional and low-level tech-guy. Because if you dont want to learn new ways and instead, if you allow your site to implement this suicide, then you are a prey of a hacker very,very soon! Sit and wait – it will quickly appear when several new updates come, and you will have no idea about updates, instead, guarding in your OLD CASTLE (which appears to have many holes).
Standard way to modify the theme
Method A:
The only case if your theme is developed by non-professionals, and it doesn’t support hooks (if you don’t know what is a hook, then please, clarify that. I.E., read this), then yes, the only way could be to modify that original files, but at least, you should rename the theme folder to theme-name_modified (or even, something random name,like buristaxto ) and also rename that in theme’s style.css heading! Now, you can modify your original files, but note, that isn’t a brilliant way either.
Method B:
The only acceptable (at least, for me) way to modify WP website functionalities and styles, is to create your personal-custom library plugin, which you can modify anytime freely. It’s quite simple, follow the steps to create your blank plugin-file:
- At first, on your desktop, create a folder, i.e. “my-custom-plugin” and inside that, create index.php (or you can just copy that from another plugin).
- Put this lines in the clean index.php:
<?php /** * Plugin Name: my-custom-plugin * Description: My Special Custom Plugin * Version: 1.1 */ add_action( 'wp_enqueue_scripts', 'add_my_scripts' ); function add_my_scripts() { wp_enqueue_style( 'my-custom-style', plugin_dir_url( __FILE__ ) . '/mystyle.css', array(), '1.1', 'all'); } //add_action( 'wp_footer', 'my_footer_message' ); function my_footer_message() { echo "Hi, i am a custom plugin"; ?> <script> alert("I am a custom JS code"); </script> <?php }
- Now, in the same folder, create mystyle.css and put your all custom styles there (no need any headers there, start CSS codes from first line at all)
Now, it’s ready! Upload your “my-custom-plugin” folder into your plugins and activate it. THAT’S ALL! From now, you wont fear of WordPress, plugin or theme updates (unless something major change happens, and even that change shouldn’t be a pain).
However, as a last advice, I have to admit, that if your theme is satisfying for you, and you don’t need any updates, then you should rename it (like described above) and leave it un-updated, but REMEMBER NOT TO MODIFY ITS PHP FILES CUSTOMLY, instead, utilise hooks from your plugin, like shown in above examples.