close
How to Software

WordPress Ads Between Posts – Plugin or Plugin-free

Are you having trouble to find ways to monetize your WordPress website? Don’t worry, we’ve got you covered! If you’re looking to increase your revenue through advertising, then you’re in the right place. While many people believe that inserting ads manually in each post or having a fixed layout for them is the only way, there are actually multiple ways to achieve this. In fact, we’ll show you how to insert ads between posts after a specific paragraph, with or without a plugin.

If you prefer using plugins to manage your website’s advertisement placements, there are several options available. These plugins are free to use and easy to manage, making them an ideal choice for those who are not familiar with coding. Some of the most popular plugins for managing advertisements include Ad Inserter, WP Quads, including the built-in auto ads adsense. These plugins come with a variety of features that allow you to manage the placement, size, and type of ads on your website.

However, if you’re comfortable with coding, you can also insert ads between posts manually by adding PHP code to your WordPress website’s single.php or functions.php file. This method gives you more control over the placement and appearance of your ads, allowing you to create a custom layout that suits your needs. Just be sure to test the code on a development version of your website before implementing it on your live site to avoid any potential errors.

There are various plugins available that can help you manage advertisement placement on your website. Below are some popular plugins that are free to use and easy to manage:

Using WordPress Ad Inserter Plugins

Ad Inserter Ad Inserter is a highly-rated plugin that offers a variety of ad placement options, including between posts. With this plugin, you can insert ads based on categories, tags, post types, and more. It also offers advanced options such as excluding ads from specific pages or posts.

ads inserter
Ad Inserter Menu

Ad Inserter is a versatile and popular plugin that can help you insert ads between posts on your WordPress website. One of the most appealing features of this plugin is the ability to place ads based on various criteria, such as categories, tags, post types, and more. This allows for a more targeted approach to advertising, which can be particularly useful for niche websites.

Additionally, Ad Inserter offers a range of advanced options that allow for greater customization and control over where your ads appear. For example, you can exclude ads from specific pages or posts, or specify the exact location within a post where you want your ad to appear.

Ad Inserter: Enabling Html settings to determine the are where to add specific advertisement code

Another useful feature of Ad Inserter is the ability to insert ad code from a range of different sources, including Google AdSense, Amazon Native Shopping Ads, and more. This makes it a flexible solution for managing various types of ads across your website.

Ad Inserter is a powerful tool for managing your website’s advertising strategy. Whether you’re a beginner or an experienced user, this plugin offers a range of options to help you achieve your goals.

Using WordPress WP Quads Plugins

WP In Post Ads WP In Post Ads enables you to insert ads in your post content using shortcodes. This plugin also offers the option to display ads based on specific categories or tags.

WP In Post Ads is a plugin that allows you to easily insert ads within your post content on WordPress. This plugin offers a range of features, including the ability to display ads based on specific criteria, such as post type or category. This allows for a more targeted approach to advertising and can help to improve the effectiveness of your ads.

One of the key benefits of WP In Post Ads is that it offers a range of ad placement options. For example, you can choose to display ads before or after your post content, or even within your post content itself. This provides a high degree of flexibility when it comes to ad placement, which can be particularly useful for those who are looking to optimize their advertising strategy.

Another useful feature of WP In Post Ads is the ability to track ad impressions and clicks. This allows you to monitor the performance of your ads and make adjustments as needed to improve their effectiveness.

Overall, WP In Post Ads is a powerful plugin that can help you take your advertising strategy to the next level. Whether you’re a beginner or an experienced user, this plugin offers a range of features and customization options to help you achieve your goals.

Turning Adsense Auto Ads Banner Ads

To enable automatic ad display in your WordPress content through AdSense, you need to follow a few steps. First, go to your AdSense ads settings and turn on auto ads. This will give AdSense permission to automatically place ads on your site. Next, select the in-page formats option and check the banner ads option.

Auto Ads
Enable Auto Ads and Check Banner Ads

This will ensure that banner ads are displayed in between the content of your WordPress site. Keep in mind that while auto ads can be a convenient way to monetize your site, it’s important to ensure that they don’t negatively impact user experience or violate AdSense policies.

Inserting Ads Directly to Your WordPress Content

It’s easy to insert code directly into your content in WordPress. Simply select “Custom HTML” in the block editor and paste your code. This is a useful option if you want to insert custom elements or embed third-party content directly into your posts or pages.

Ads in Content
Inserting Ads Directly to the content

However, it’s important to note that inserting code can be risky, especially if you’re not familiar with coding. Improperly formatted code or code that conflicts with your website’s theme or plugins can cause errors or even break your website. Make sure to double-check your code and test it thoroughly before publishing it on your live site.

Using Code Changes to Insert Ads Between Posts:

If you prefer not to use a plugin, it’s possible to achieve the same result through code changes. Here’s how:

  1. Locate your theme’s single.php file You can access your theme’s files via Appearance > Editor in your WordPress dashboard. Look for the single.php file, which controls how individual posts are displayed.
  2. Insert ad code where you want your ads to appear You can insert your ad code directly into the single.php file, between the post content, using HTML. If you want your ads to appear after a specific paragraph, you can use the <?php if (paragraph number) : ?> conditional tag.
  3. Save your changes Once you’ve added your ad code, save your changes to the single.php file.

Final Thoughts:

Insert Ads Between Posts in WordPress Using PHP Code

This code is used to insert ads into WordPress blog posts automatically. The function add_filter adds a filter to the content of a WordPress post or page, and calls the insert_post_ads function.

The insert_post_ads function defines a few variables, including an example ad code and an array of paragraph IDs. It counts the number of paragraphs in the post content, and then filters the $paragraph_ids array to only include paragraph IDs that exist in the post content.

If the current page is a single post and the user is not an admin, the function loops through each paragraph ID in the filtered array and calls the prefix_insert_after_paragraph function to insert the ad code after the corresponding paragraph in the post content.

The prefix_insert_after_paragraph function takes the ad code, the paragraph ID, and the post content as parameters. It splits the post content into an array of paragraphs, then loops through the array to find the paragraph ID that matches the one passed to the function. Once found, it appends the ad code to the e

Insert Ads Between Posts Code You Need to put in Functions.php

add_filter( 'the_content', 'insert_post_ads' );

function insert_post_ads( $content ) {

    $ad_code = '<div><p>test code </p>Insert your Ads code here</div>';
    $paragraph_ids = array(3, 6, 9); // Example array of paragraph IDs
    $num_paragraphs = substr_count( $content, '</p>' ); // Count number of paragraphs in content

    // Adjust $paragraph_ids array to only include existing paragraph IDs
    $paragraph_ids = array_filter( $paragraph_ids, function( $id ) use ( $num_paragraphs ) {
        return $id <= $num_paragraphs;
    } );

    if ( is_single() && ! is_admin() ) {
        foreach ( $paragraph_ids as $paragraph_id ) {
            $content = prefix_insert_after_paragraph( $ad_code, $paragraph_id, $content );
        }
        return $content;
    }

    return $content;
}

// Parent Function
function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
    $closing_p = '</p>';
    $paragraphs = explode( $closing_p, $content );
    foreach ( $paragraphs as $index => $paragraph ) {

        if ( trim( $paragraph ) ) {
            $paragraphs[$index] .= $closing_p;
        }

        if ( $paragraph_id == $index + 1 ) {
            $paragraphs[$index] .= $insertion;
        }
    }

    return implode( '', $paragraphs );
}

Overall, this code is useful for automatically inserting ads into a WordPress blog post without having to manually edit the content every time.

Whether you choose to use a plugin or code changes to insert ads between your post content, it’s important to be mindful of not overloading your website with too many ads. Finding a balance between monetization and user experience is key. With these methods, you can start displaying ads in a way that works best for you and your website.

Please note that before implementing any code in your WordPress site, it is important to test it thoroughly in a development environment to avoid any potential errors or issues. Failure to do so can result in errors on your live site, causing inconvenience to your visitors. It’s always better to take the time to test your code before implementing it in your live production site.

Tags : PluginsWeb Development
Joemar Bagalanon

The author Joemar Bagalanon

I’m a tech enthusiast with a diverse background in Computer Repair, Multimedia Arts, and Computer Science. With experience owning an Internet café and working as an IT Technician for SME businesses, I’ve gained hands-on expertise in troubleshooting software and hardware issues. Passionate about sharing knowledge, I stay updated with the latest in technology to inspire others through my writing and insights.