show-ads-between-images

Many manga website owners look for a way to show ads between images of a chapter to improve monetization without disrupting the reading experience. While the Madara theme does not provide this feature by default, you can achieve it using the ‘madara_after_chapter_image’ hook.

How to Insert Ads Between Images

To enable showing ads between images of a chapter, add the following code to your child theme’s functions.php file:

php
add_action('madara_after_chapter_image', 'my_madara_ads_between_images', 10, 2); function my_madara_ads_between_images($paged, $total_pages){ if(($paged % 3) == 0){ ?> <img src="https://yoursite.com/wp-content/uploads/banner-ads.jpg" alt="Ad Banner"/> <?php } }

This function ensures an ad is displayed after every third image in a chapter. You can replace the <img> tag with HTML or JavaScript ads, such as Google AdSense or affiliate banners.

Display Ads for Specific Manga or Chapters

If you want to control ad placement for specific manga titles or chapters, use the following conditional check:

php
$chapter_slug = get_query_var('chapter'); $manga_id = get_the_ID(); if ($manga_id == 100 && $chapter_slug == 'your-chapter-slug') { // Insert your ad code here }

This ensures that ads appear only in certain manga chapters, allowing more targeted advertising.

Why Use Ads Between Chapter Images?

Adding ads between images can improve revenue while maintaining user experience. Instead of displaying ads in distracting locations, this method blends them seamlessly into the reading flow.

For more customization, you can explore the Madara theme documentation or check our guide on optimizing manga websites for better performance and monetization strategies.

SHARE THIS POST

1 Comment

  1. Jeff Hung

    I tried using the code provided but I got errors:

    add_action(‘madara_after_chapter_image’, ‘my_madara_ads_between_images’, 10, 2);

    function my_madara_ads_between_images($paged, $total_pages){

    if($paged == 3){

    ?>

    <?php

    }

    }

    But after putting this code in the functions page of my child this, this is the error that shows up top:

    Warning: Use of undefined constant ‘madara_after_chapter_image’ – assumed '‘madara_after_chapter_image’' (this will throw an Error in a future version of PHP) in /home/neatmanga/public_html/wp-content/themes/madara-child/functions.php on line 114

    Warning: Use of undefined constant ‘my_madara_ads_between_images’ – assumed '‘my_madara_ads_between_images’' (this will throw an Error in a future version of PHP) in /home/neatmanga/public_html/wp-content/themes/madara-child/functions.php on line 114

Leave a Reply