Stats: 3,192,028 members, 7,946,461 topics. Date: Wednesday, 11 September 2024 at 06:29 PM |
Nairaland Forum / Science/Technology / Webmasters / Simply Place Your Google Adsense Ads Anywhere With These Functions (835 Views)
Block Low Adsense Ads And Make 5$ Per Clicks. / How Can I Check The Individual Prices Of Adsense Ads? / 7 Reasons Why You Aren't Getting Enough Clicks On Your Adsense Ads - Mediapace (2) (3) (4)
Simply Place Your Google Adsense Ads Anywhere With These Functions by Nobody: 7:09pm On Jun 13, 2016 |
Where Do You Want Your Adsense Ads To Appear? . The other day, a friend asked me if it is possible for him to easily display his google adsense ads on all his blog pages. I told him it is possible, but that it depends on which platform powers his blog. So, today I will show you two easy ways to post your google ads in any sections of your blog/web pages; i.e. before your main post; before your post title; after your post title, below your post content, etc. . We will create two simple PHP functions: the first function should "ONLY" be used by those who have a self-hosted Wordpress.org blog/website. The second function can be used by those who have access to the source code of their blog/website. . Note:: You don't have to edit any part of your blog's source code! Just follow the instructions which I willl be posting shortly. Read on. |
Re: Simply Place Your Google Adsense Ads Anywhere With These Functions by Nobody: 7:38pm On Jun 13, 2016 |
For Wordpress Users . Step 1: Back up your website from your admin dashboard or use your host's website back up service. This is to help you be on the save side incase there is a file corruption during this operation. . Step 2: Using your favourite FTP Client like FileZilla, connect to your server and then navigate to your website's/blog's root folder. Download ONLY your wp_contents folder/directory from the wordpress root directory and save it in your desktop. . Step 3: You now have the wp_contents folder on your desktop. For now, you can disconnect from the server. Open the folder and look for a file called functions.php. Open the file and add the following code on step 4. Add the code immediately below all existing codes in the file. . Posting shortly... |
Re: Simply Place Your Google Adsense Ads Anywhere With These Functions by Nobody: 8:56pm On Jun 13, 2016 |
Step 4: Add the following code to your functions.php file. You can just copy and past it below all existing codes in the file. . <?php function my_custom_adsense() { /*let's create a room for our unique adsense id*/ $adsenseID = array(); $adsenseID["PUT-YOUR-ID-HERE"]; } add_action('my_custom_adsense', 'my_custom_adsense'); ?> . Note: Replace "PUT-YOUR-ID-HERE" with your unique adsense ID. Put your ID within the double quotation marks. Save the file. . Step 5: Now open any other template files in your wp_contents folder where you want your add to be displayed and add the following short code. For instance, if I want my ads to display above my home page, I will open home.php or index.php and add the following short code: . do_action('my_custom_adsense'); . Some people like to display their ads in the main posts template/page. In that case open the single.php file and add the short code on top of where you see the_title() or any where you want it. . Continued... |
Re: Simply Place Your Google Adsense Ads Anywhere With These Functions by Nobody: 9:18pm On Jun 13, 2016 |
Step 6: Now after adding the short code in any of your template files, remember to save them. DO NOT ADD OR REMOVE ANYTHING EXTRA. . Step 7: Bring up your FTP client and connect to your web server. Upload the entire wp_contents folder to the wordpress root directory/folder. When asked whether to override the existing folder, just click yes. . Step 8: Clear your cache (if there) and refresh your website. If everything went right, your ads should now display. Otherwise, read the above steps carefully. . That's it! For others who are not using the wordpress blogging platform, follow the instructions below. Please note that the following steps apply only to those who have FULL access to the source code of their website/blog. . Details in a moment... 1 Like |
Re: Simply Place Your Google Adsense Ads Anywhere With These Functions by internetonline: 9:27pm On Jun 13, 2016 |
it takes a wordpress developer like you and i to really understand wordpress hooks, actions and filters. its a cool tutorial but i suggest you teach the use of plugins for the general benefit of those not too technically inclined. Only those that are into wordpress themes development like you and and i can really understand what functions.php, single.php and other tempplate pages are for. All the same , you are corrrect just that in your custom function, you are not passing the adsense ID as a variable to the function. why is that? any reason. would like to know. kudos Happy coding. 1 Like |
Re: Simply Place Your Google Adsense Ads Anywhere With These Functions by Nobody: 10:31pm On Jun 13, 2016 |
For Other Blogging Platforms Step 1: Create a text file using a plain Text Editor like Notepad. Inside the file, copy and paste your unique google adsense ID and save the file as adsense_id.txt Create a folder on your desktop and name it adsense_id. Save the adsense_id.txt file in this folder. . Step 2: Create another text file and put the following code in it: <? //include file function show_ads() { include_once('../adsense_id/adsense_id.txt'); } ?> . Save this file as show_ads.php.Under "File Type", select "All Files". Create a folder and name it show_ads. Put the show_ads.php file in it. . Step 3: Connect to your web host. Upload the adsense_id and show_ads folders into the root folder of your website. . Step 4: Open any of your PHP template files and just put this code any where you'll like your ads to appear: . show_ads(); . That's it! Share your experience... 1 Like |
Re: Simply Place Your Google Adsense Ads Anywhere With These Functions by Nobody: 11:12pm On Jun 13, 2016 |
internetonline:Hello InternetOnline! Thanks for stopping by... In the custom function, I avoided using a global variable since NO OTHER function within the script will need to reference the variable. However, declaring a global variable and then calling it within the custom function MIGHT equally work. |
Re: Simply Place Your Google Adsense Ads Anywhere With These Functions by wizkidblogger(f): 12:01pm On Jun 14, 2016 |
Long thing. There are cool plugins that makenthisbvery easy to implement. Well done though... |
Re: Simply Place Your Google Adsense Ads Anywhere With These Functions by Nobody: 10:10pm On Jun 14, 2016 |
wizkidblogger:Thanks there! But activating too many plugins can have a negative impact on your website/blog. Some plugins create EXTRA database tables which can affect the database engine -- resulting in slow page presentation. Sometimes getting something done with a short line of code can save you future headaches. Thanks for stopping by. |
Re: Simply Place Your Google Adsense Ads Anywhere With These Functions by peteregwu(m): 8:53am On Jun 15, 2016 |
You guys are just hot in this Web design of a thing. Wish I would know this things. 1 Like |
(1) (Reply)
00webhosting Free Web Hosting / Top 15 Content Delivery Network Providers / .
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 32 |