How to Add Adsense Code to WordPress Without Plugin 2024

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

  1. Log in to Your WordPress Admin Dashboard:
    Go to yourdomain.com/wp-admin.
  2. Navigate to the Theme Editor:
  • Go to Appearance > Theme Editor (or Appearance > Editor depending on your WordPress version).
  1. 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 in header.php or footer.php is common.
  1. 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.
  1. Save the Changes:
  • Click the Update File button to save the changes.
  1. Verify the Ads:
  • Visit your website to ensure the ads appear as expected.

Method 2: Using the WordPress Customizer

  1. Log in to Your WordPress Admin Dashboard:
    Go to yourdomain.com/wp-admin.
  2. Navigate to the Customizer:
  • Go to Appearance > Customize.
  1. Add Custom Code (if available):
  • Some themes have an option like Additional CSS or Custom Code where you can add scripts. If your theme has this option, paste your AdSense code here.
  1. 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.
  1. Publish Your Changes:
  • Click Publish to apply the changes.

Method 3: Using the functions.php File (Advanced)

  1. Log in to Your WordPress Admin Dashboard:
    Go to yourdomain.com/wp-admin.
  2. Navigate to the Theme Editor:
  • Go to Appearance > Theme Editor.
  1. Select the functions.php File:
  • Choose functions.php from the Theme Files section.
  1. 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.
  1. Save the Changes:
  • Click Update File.
  1. 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.

Shopping Basket