Free plugins are awesome and most can be used with no fear, but let’s face it, bad things do happen at times. Yesterday I discovered that author of my Adsense plugin decided he could earn from my site. All my ads disappeared and were replaced with his ads 😐
The plugin was quite simple, it was basically shortcodes that I had to insert manually to all my pages. Although there are automated solutions, I prefer it this way, because I control how and where my ads appear.
Needless to say, I got rid of his plugin immediately. There was no serious harm to my site, but I still needed a solution for my ads.
Having to install another plugin didn’t seem like an attractive idea. Going through hundreds of pages removing his shortcodes and replacing with something new was out of question. I needed to get my old broken shortcode work the way it did without plugin.
His shortcode looked like this
[wp_ad_camp_1]
It was inserted into each post of my site. Normally it was displaying ads, but now my visitors were seeing ugly [wp_ad_camp_1] in between paragraphs…
Fortunately, this was easy to fix. I went to my WordPress files in cPanel wp-content –> Themes –> My Current Theme folder –> functions.php
I added this to my functions.php (at the end)
/*MY AD SHORTCODES*/ function MyPersonalShortcode() { return 'AD CODE GOES HERE'; } add_shortcode('wp_ad_camp_1', 'MyPersonalShortcode');
Voila, I am a big girl now. My ads are running. I don’t need your plugin!
Pay attention: I made sure I have wp_ad_camp_1 in the last line, because it should match the old shortcode exactly. Anything would work, but the whole point is to get your old broken shortcode do what you want it to do. So if you ever find yourself in similar situation, make sure you insert exactly same shortcode name as your old shortcode. Function MyPersonalShortcode can be anything you wish.
Obviously, AD CODE GOES HERE has to be replaced with your ad or piece of text you want to display.
Warning:
1. Backup your functions.php before editing.
2. When you edit, make sure you leave no empty spaces in your functions.php – that is before the first line of code and after the last line. It’s really easy to leave spaces without realizing and what you get is that you can’t access your WordPress admin area – you’ll get a blank screen instead. If you manage to access your dashboard, you are likely to have issues with Media gallery, and when saving any new modifications. You’ll be getting blank screen every time. While it sounds and looks very scary, the fix is easy – go back to your functions.php and remove empty lines. Hit Save and you should be fine.
3. This code is very simple. There are more sophisticated ways of doing this. However this is enough to insert an ad or a piece of text in place of your shortcodes.
4. If your site is completely messed up after modifying functions.php, you did something wrong :p Don’t worry, just get rid of any new code you just inserted and hit save again. You’ll be back to your old version. Now you can take time to think what you did wrong then try again.