If you are not blogging just for pleasure, you need to display ads on your site, on your sidebar, on your header, wherever you consider them necessary. In order to protect your WordPress site from being penalized by the mighty Google, you have to display your ads moderately. I’m sure that almost all the WordPress.org sites users know how to deal around with theme customizations, code snippets, and other modifications. Just in case, and for the rest of proudly WP users, I want to show here a piece of PHP code you place on your functions.php file, on your WP blog/site. It is really simple, but you have to remember to ad your shortcode every time you post.
[source]
For Genesis Framework lucky users, there are more methods, for example, to put the code in the Genesis Simple Hooks display, where one considers it would be more suitable to show the ad. I prefer the 728×90 pixels type wherever there is enough room for it. As you notice, I already have one in the header. It is said that the ones inside the post are best suited for quality advertising on your blog.
Doesn’t really matter what kind of advertising code one uses, it can be chitika, bidvertiser, or other, for the snippet I’m going to show you below.
First, you have to open your Editor! It is placed in the Appearance panel, on the left of your dashboard.
Because by default the editor opens on your stylesheet (style.css), you have to open your functions.php file, as showed below:
After that, you scroll down to the end, leave an empty line and type (or copy and paste) the following snippet:
function myAdSenseCodeFunction(){
return 'Your AdSense Code Goes Here';
}
add_shortcode('ad', 'myAdSenseCodeFunction');
where instead of ‘Your AdSense Code Goes Here’, between the apostrophes, you paste the code you take from your adsense account.
I tried to paste it here, live, but it won’t appear, it’s a matter of confidentiality 🙂
After that, wherever you type [ad] inside your post (of course, you have to turn it on Text viewing, not on Visual ), when you hit publish, a chosen type advert will appear.
You can adapt this at every type of code. Take care to the apostrophes and the brackets! I suggest this shortcode because it is simpler to type [ad] between two lines, than to copy the entire code every time and paste it into your post, which can be confusing 🙂
Good luck! I hope this has been helpful. It is pure PHP. You can replace ‘ad’ with ‘a’ in the code, or with any letter you find more suitable, a simple ‘c’, or an ‘x’, or a ‘b’, as you like, but don’t forget to keep the same letter to be typed inside your posts, between brackets: [a], [c], [x], or [c], respectively.
If you use other advertising platform, you can adapt the code as follows:
function myChitikaCodeFunction(){
return 'Your Chitika Code Goes Here';
}
add_shortcode('c', 'myChitikaCodeFunction');
Of course that instead of ‘Your Chitika Code Goes Here’, there will be the code you have copied from your chitika account, and the shortcode to insert will be [c]. (This is only an example, I hope you are aware of that.)
Remember! [ad] or [c] or no matter what are you using, is the shortcode. This is what you remember by heart, and you type in your text editor of your blog post.
If you want to use two or three advertising platforms, and you want to insert shortcodes from all these platforms in your posts, you can add the snippets one after the other (always leaving an empty line between them) , but you have to be careful to change the syntax as I have showed above, to make a difference between them. It’s common sense!
I don’t recommend more than two platforms at a time, but it is up to you to not be annoying for your visitors. I also do not recommend bidvertiser. Their code is messing with your site design, leaving you no means for control, and is noticeably annoying your serious visitors! Beside that, the bidvertiser code leaves your site as you are some kind of retard who doesn’t have any clue to designing. It also pays irrelevantly amounts, even if they pay quicker than adsense. Their code used to be customizable, but not anymore.
Stick with Google in this, it’s the only thing they do best beside searching. Even your searching is designed to make you leave clues for them on what kind of ads to “serve” you when you visit any other site that’s using adsense.
If you liked what you read (and for that I humbly thank you for your patience), subscribe to this blog by Email! Follow this blog on Twitter, and on Facebook! For a joyous day, check out my pins on Pinterest or my grams on Instagram 😄. I hope you like this blog so much that you think it’s time to take a step further by becoming yourself a blogger; in order to do that have the kindness to read the Own Your Website offer I have prepared for you! You won’t regret. Thanks for passing by 😄 Speak your mind, don’t be shy!
Copyright © 2015 Rodolfo Grimaldi Blog – Create a Shortcode for Adding Adsense Adverts on Your Posts
Anna says
Simple but not everybody knew it.
Oscar Gonzalez says
Pretty clever. Thanks for sharing!
Daniel Mihai Popescu says
You are welcome 🙂
Reza says
great. thanks
Duronto Azam says
Nice Trick.
Daniel Mihai Popescu says
Not quite a trick 🙂