how to paste google adsense code in wordpress without plugin
how to add adsense code to wordpress (Urdu/Hindi) 2024
how to add adsense code to wordpress without plugin
how to add code in wordpress header #googleadsense
Adding AdSense code to WordPress without a plugin involves editing your theme’s files or using the WordPress Customizer. Here’s a step-by-step guide:
Method 1: Using the Theme Editor
- Log in to Your WordPress Admin Dashboard:
Go toyourdomain.com/wp-admin
. - Navigate to the Theme Editor:
- Go to
Appearance
>Theme Editor
(orAppearance
>Editor
depending on your WordPress version).
- Select the Theme File to Edit:
- In the Theme Files section, choose
header.php
,footer.php
, or a specific template file where you want the ads to appear. Typically, placing code inheader.php
orfooter.php
is common.
- Insert the AdSense Code:
- Copy the AdSense code from your Google AdSense account.
- Paste it into the desired location within the selected file. For example, to place ads in the header, paste the code just before the
</head>
tag.
- Save the Changes:
- Click the
Update File
button to save the changes.
- Verify the Ads:
- Visit your website to ensure the ads appear as expected.
Method 2: Using the WordPress Customizer
- Log in to Your WordPress Admin Dashboard:
Go toyourdomain.com/wp-admin
. - Navigate to the Customizer:
- Go to
Appearance
>Customize
.
- Add Custom Code (if available):
- Some themes have an option like
Additional CSS
orCustom Code
where you can add scripts. If your theme has this option, paste your AdSense code here.
- Use a Custom HTML Widget (for Sidebars or Widgets Areas):
- Go to
Appearance
>Widgets
. - Add a
Custom HTML
widget to your sidebar or other widget areas. - Paste your AdSense code into the widget and save.
- Publish Your Changes:
- Click
Publish
to apply the changes.
Method 3: Using the functions.php File (Advanced)
- Log in to Your WordPress Admin Dashboard:
Go toyourdomain.com/wp-admin
. - Navigate to the Theme Editor:
- Go to
Appearance
>Theme Editor
.
- Select the
functions.php
File:
- Choose
functions.php
from the Theme Files section.
- Add a Function to Insert AdSense Code:
- Add a function to output the AdSense code. For example:
php function add_adsense_code() { ?> <!-- Your AdSense Code Here --> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-XXXXXX", enable_page_level_ads: true }); </script> <?php } add_action('wp_footer', 'add_adsense_code'); // Adds AdSense code to footer
- Replace
<!-- Your AdSense Code Here -->
with your actual AdSense code.
- Save the Changes:
- Click
Update File
.
- Verify the Ads:
- Visit your website to ensure the ads are displaying correctly.
Note: Directly editing theme files requires caution, as incorrect changes can break your site. It’s recommended to use a child theme or create backups before making changes. If you’re uncomfortable with code, using a plugin might be a safer and easier option.