As the title goes, this tutorial will pretty much try to cover (at a beginner level) all the steps that need to be taken in order to have the power of choosing in which articles and where exactly to post your ad blocks. An ad block can be AdSense, AdBrite, basically it doesn’t matter if it’s a link to an image or a JavaScript piece of code. The advantage of doing this is that you can always prepare something new for your readers. You won’t always get to have that 468×60 under your post because having the same positions for the ads will make them invisible for your visitors. So I will show you how to get things in control and put those ads where you want, and when you want them.
The first thing you’ll need to do is to open yourfunctions.phpfile of your theme with a basic text editor (Notepad will do). If you don’t have one, just create the file now (it should be located in your theme’s folder). Add the following piece of code to the end of the file (in this tutorial I will be editing the functions.php file of the default theme):
function adsense_shortcode( $atts ) {
extract(shortcode_atts(array(
‘format’ => ‘1’,
), $atts));
switch ($format) {
case 1 :
$ad = ‘
';
break;
}
return $ad;
}
add_shortcode(‘adsense’, ‘adsense_shortcode’);
All you need to do next to output the ad block in your post is to use[adsense]syntax. Notice the $ad variable. In this example it holds the basic AdSense code. Feel free to replace that code with any ad code. As I said earlier, you can have something as basic as a simple image that links to some site (with referral code or such). It is important to keep in mind the size of the code that you’re using. You probably don’t want to end up putting a wide skyscraper in your article; but then again… who knows. If you want to have different ads just duplicate the code above and instead of the following lines have adsense replaced with the new name:
function adsense_shortcode( $atts ) {
replace with
function newName_shortcode( $atts ) {
and
add_shortcode(‘adsense’, ‘adsense_shortcode’);
replace with
add_shortcode(‘newName’, ‘newName_shortcode’);
- Blogger Comment
- Facebook Comment
Subscribe to:
Post Comments
(
Atom
)
0 comments:
Post a Comment