How To Make Google AdSense Shortcodes For WordPress

Creating Google AdSense Shortcodes For WordPress

Many WordPress blogs and websites establish profit online by integrating advertisements utilizing the Google AdSense program. Google’s Adsense advertisements are written in java script and can be placed into any location which reads HTML, like WordPRess pages, posts, theme files, and text capable widgets.

Down The script below is an example of what a standard 200 x 200 Google AdSense advertisement looks like.

<script type="text/javascript"><!-- google_ad_client = "ca-pub-2336674635953969"; /* Advertisement Name */ google_ad_slot = "2720758527"; google_ad_width = 200; google_ad_height = 200; //--> </script> <script type="text/javascript" src="http://pageadd2.googlesyfndicgfion.com/pagead/showfdds.js"> </script>

Making Ad “Sense”

Google AdSense WordPress Shortcode

Google AdSense Example

If you don’t know the scripts of your Google AdSense advertisements by memory, nor have them in close proximity to copy and paste into your WordPress blog or website, the easy use of implementing your AdSense advertisements into your WordPress website at anytime you want may not yet be in existence. But there’s a very easy way to add your Google AdSense advertisements without constantly re-copying a multi-line java script code into every HTML ready nook and cranny.

The simple solution is to create a shortcode in the current WordPress theme’s functions.php file. This way Google AdSense advertisements can easily be displayed at any time by creating  the shortcode (It just makes sense): [adsense]

How To Create A Google AdSense Shortcode

Below is a PHP functions code that will create a shortcode for WordPress and will allow you to display Google AdSense advertisements. Our demo AdSense script, which we displayed once above is highlighted in gray font below. 

Down Copy and paste the code below into your functions.php file Replace ADSENSE SCRIPT HERE to your Google AdSense java script.

function adsenseads() {
    return '<div id="adsenseads">ADSENSE SCRIPT HERE</div>';
}
add_shortcode('showmyads', 'adsenseads');

To display Google Adsense advertisements use the shortcode: [adsense]

To create  multiple Google AdSense advertisement shortcodes in WordPress change only the word ‘adsense’ in the last line of the functions.php code. A suggestion is to label shortcodes for different advertisements. For example ‘adsense1’ and ‘adsense2’ will create the shortcodes [adsense1] and [adsense2]. You can even name the shortcodes after the titles of your AdSense advertisements. This is a great way to keep track of your Google AdSense advertisements in WordPress if you are always writing and need to place advertisements which configure correctly in certain spaces.

Sean Doyle

Sean is a distinguished tech author and entrepreneur with over 20 years of extensive experience in cybersecurity, privacy, malware, Google Analytics, online marketing, and various other tech domains. His expertise and contributions to the industry have been recognized in numerous esteemed publications. Sean is widely acclaimed for his sharp intellect and innovative insights, solidifying his reputation as a leading figure in the tech community. His work not only advances the field but also helps businesses and individuals navigate the complexities of the digital world.

2 Responses

  1. Mayank says:

    Thanks for this such helpful article Sean.
    As per your short code example should I not use [showmyads] as shortcode instead of [adsense]. Please correct me if I am wrong.

  2. freelance web designer kerala says:

    thanks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.