Insert ads in articles (for WordPress)

Insert ads in articles (for WordPress)

Generally speaking, we place Google Adsense ads by modifying the theme or inserting them into the left side of the article through plug-ins, or using widgets to put them in the sidebar, etc. However, if you want to insert an advertisement in the middle of an article, it is difficult to achieve through technical means or the implementation is not perfect.
Then you can use WordPress Shortcode to place Google Adsense ads, which is very convenient.
What is Shortcode
Shortcode API is a new feature added after WordPress 2.5. Simply put, it is to define a set of functions in advance, thereby generating a corresponding simple short code, and then inserting this short code anywhere in the body of the content will call the pre-defined function. For example: [galley] is the shortcode that calls the default WordPress photo gallery, which can also have parameters. For more detailed information, please refer to the official Shortcode API documentation
Use Shortcode to place Google Adsense ads <br /> Save the following code to functions.php of your current theme:

add_shortcode('adsense', 'adsense_shortcode');
function adsense_shortcode($atts) {
extract(shortcode_atts(array(
'type' => '468×60',
), $atts));
switch ($type) {
case '468×60' :
return
'468×60 ad code';
case '300×250' :
return
'300×250 ad code';
}
}

Then you can enter the corresponding position when writing the article.

[adsense]

, your 468×60 ad code will be displayed (default ad code). If you want to insert a 300×250 ad code, insert it in the article content.

[adsense type=”300×250″]

Via: http://fairyfish.net/m/shortcode-google-adsense/ and http://www.yonglanren.info/archives/2858.html

<<:  QuickPacket - Provides cost-effective dedicated servers

>>:  Introduction to Japanese [email protected]

Recommend

WootHosting: $12/year/2GB RAM/40GB storage/2TB bandwidth/OpenVZ/Phoenix

WootHosting, an American hosting company, was fou...

Altınsoft: $15/month/1GB RAM/30GB SSD space/unlimited traffic/VMware/USA

Altınsoft, a Turkish hosting provider, was establ...

Kdatacenter 1G memory 1Gbps port South Korea SK KVM VPS review

Details : Kdatacenter: $17.1/month/1G memory/100G...

HostUS: $12/year/768MB memory/20GB space/2TB traffic/OpenVZ/Los Angeles

HostUS is a good VPS at a low price. Here are all...

CloudCone: $1.75/month/512MB memory/20GB SSD space/2TB traffic/KVM/Los Angeles

CloudCone, a recently active hosting provider, pr...

HostSailor 512MB RAM 1Gbit Bandwidth Netherlands KVM VPS Review

Details : HostSailor: $6.6/year/256MB memory/10GB...