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

RackHost: $3.5/month/512MB RAM/10GB SSD/Unlimited traffic/KVM/Netherlands

RackHost, a Romanian hosting provider under ITDat...

Digitalocean offers a $10 discount code

Coupon code: SSDTWTTR The usage is still the same...

Hostibox: $5/month/2GB RAM/10GB SSD space/unlimited traffic/KVM/West Virginia

Hostibox, a foreign hosting provider, claims to h...

.cu.cc: Free, resolvable, changeable DNS secondary domain name

Registration address: http://www.registry.cu.cc/ ...

DeinServerHost: €10/month/10GB RAM/50GB SSD space/5TB traffic/DDOS/KVM/Germany

DeinServerHost, a German hosting provider, was es...

PeakServers: $6/year/256MB RAM/10GB storage/500GB bandwidth/1 IP/OpenVZ

PeakServers, I have introduced it many times on A...

Programs that can use free space to build proxies

The programs are very simple to build, and the re...

PeakServers:$19/year/1 CPU/1G/25G/2T/1 IP/OpenVZ

PeakServers has been introduced several times on ...