Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

How to Add Google AdSense to Your WordPress Site Without a Plugin

June 13, 2022
in Blog, Wordpress
0
ADVERTISEMENT

Table of Contents

Manually Place Google AdSense Ad Code in WordPress

You’ll start by clicking on the Ads menu in the left column and then switching to the ‘By ad unit’ tab. From here, you need to click on ‘Create New Ad.’

You will be asked to choose an ad type. You can select from Display ads, In-feed ads, and In-article ads. If you are unsure, then start with the display ads.

Bg580

Next, you need to provide a name for this ad unit and select the ad size and type. The name of the Ad is only used for internal purposes so you can name it anything like “my-ads-code.”

The next option is choosing the Ad Size. While Google offers a wide variety of ad sizes, there are certain sizes that are listed under recommended because those are the most popular among advertisers.

You can also choose whether you want your ad to be responsive or fixed. We recommend choosing responsive ads as they work well on all devices and screen sizes. Guidelines for fixed-sized display ad units.

Bg581

Next, click on the Create button to continue. AdSense will now generate the ad code for you. It contains the unique ad unit ID and your publisher ID.

Bg583

Adding Google AdSense in WordPress

Next, you need to determine where you want to show the ad on your website. Ads are most commonly displayed in the sidebar.

Simply go to the Appearance » Widgets page in your WordPress admin area to add a Custom HTML widget block to the appropriate widget area.

Bg589

Next, you’ll need to enter the Google AdSense code in the Custom HTML widget block. After that, don’t forget to click the ‘Save’ button.

Bg590

The ads was showed in the sidebar of all post page of your WordPress site.

Bg594

Adding Google AdSense in WordPress using Shortcode

In some cases, you want to add Google Ads into more than one location as the sidebar. You can create a shortcode to show the ads on your site. How to Create Your Own Custom Shortcode in WordPress Without a Plugin

For example, i’ll create a shortcode to show Google Ads by edit Theme Functions (functions.php).

Bg584
// The shortcode function
function ads_shortcode() { 
  
// Advertisement code pasted inside a variable
$string .= '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3352438238321589"
     crossorigin="anonymous"></script>
<!-- my-ads-code -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-3352438238321589"
     data-ad-slot="4743305961"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>';
  
// Ad code returned
return $string; 
  
}
// Register shortcode
add_shortcode('my-ads-code', 'ads_shortcode');

You can now use add this shortcode to your posts, pages, widgets and the theme file using the following code: [my-ads-code]. It will run the function you created and show the desired output.

Adding the ads shortcode into the widget block:

Bg595

Adding the shortcode into a PHP theme file:

Bg593

Adding the shortcode into a post directly:

Bg579

Or you can using shortcode if your WordPress theme supports add it directly.

Bg596

Add Auto-Ads AdSense Code in WordPress

Adding individual ads to different areas of your website takes a lot of time. Most beginners struggle to find the best locations to display ads on their sites.

To solve this, Google introduced auto-ads. This allows you to simply add one code snippet to your site and let Google AdSense figure out the highest paying location, ad size, and type.

The disadvantage of this method is that you have less control over ad placement on your website. If you want to use the auto-ads feature, then this is how you’ll add Google AdSense to your website.

Bg597

AdSense will now generate a code snippet with your publisher ID and display it. You can now copy and paste this code into a text editor.

Bg598

Adding AdSense Auto-Ads Code in WordPress

The auto-ads code uses a single code snippet to generate ads everywhere on your WordPress blog. This means you need to add the code to all the pages where you want to display the ad.

One way to do this is by adding the code in your WordPress theme’s header.php or footer.php file.

Note However, the disadvantage of this method is that your ad code will disappear if you update or change your theme. So make sure you add the code into the header of your child theme.
Bg599

Now the ad code is ready to show on all pages of your website. It may take Google AdSense some time to start showing ads.

5/5 - (1 vote)
Previous Post

How to Create Your Own Custom Shortcode in WordPress Without a Plugin

Next Post

How to Download and Install Office 2019 Click to Run

Related Posts

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024
Ftr19

How to Fix Windows Cannot Read the ProductKey From the Unattend Answer File in VirtualBox

July 26, 2024
Ftr25

How to Update Windows Terminal in Windows 10/11

July 26, 2024

How to Disable The Beep Sound in WSL Terminal on Windows

July 26, 2024

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory