Inserting ads in between posts is one of the best ways to get clicks and get visitor attention.
There are many plugins out there to dynamically insert ads in between/inline paragraphs in a post.
But what if you want to keep it simple to manually insert ads in posts and pages as and when needed?
The normal way:
Copy the ad code and paste it into the editor.
This works but the problem is if you want to change the ad code in the future, then you have to edit all the posts one by one. This is inconvenient.
The Shortcodes way:
We can create “shortcodes” for such ad code snippets and then use the shortcode. Shortcoder is one such plugin to create shortcodes for HTML, CSS, and JavaScript code snippets.
Installing Shortcoder
Shortcoder is a free plugin available in the WordPress plugin repository. Go to your WordPress admin dashboard.
Head over to Plugins > Add new page. Search for “Shortcoder”, click install, and activate the plugin.
Creating Shortcodes for Ad snippets
Go Shortcoder > “Create shortcode” page.
Give a name for the shortcode. Let’s name it “adsense-inline”. Our shortcode will be [sc name="adsense-inline"]
now.
In the shortcode content, paste the Google Adsense code.
Save the shortcode and that’s it.
You have now created a Shortcode for the AdSense code. You can now use this shortcode inside posts and pages.
[sc name="adsense-inline"]
It would be then replaced with the AdSense code you have set as shortcode content.
You can create multiple shortcodes for code snippets like this.
Hiding the Shortcode for Administrators
What if you as an administrator do not want to see the ads you are displaying via the shortcodes you created above?
Shortcoder even provides an option to “Disable shortcode for administrators” on the shortcode edit page.
Now when you are logged in to your site and when you visit a page where this shortcode is present, it won’t be executed.
Let’s say you want to temporarily disable executing the shortcode for all users. You can select “Temporarily disable shortcode” to “Yes” and it will stop displaying everywhere for all. This is beneficial in some use cases.
Conclusion
As we saw it is very easy to create shortcodes for Google Adsense code snippets. Check out Shortcoder plugin if you have similar use cases to reuse simple static code snippets.
If you have any comments, feel free to share them in the comments section below.
Add your comment No Comments so far