2019-01-09_095917

Some customers ask for the ability to add banners between chapter images. We do not want to add an option for that in the theme, but leave a way to hack that. It’s the hook ‘madara_after_chapter_image‘ that you can use. Here’s the guide.

Put this code your  child theme functions.php file

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/banner.ads"/>

<?php

}

}

The above code will show an image (as a banner) after the 3rd image in your chapter reading page. The ads could be anything, HTML code or Javascript code. I leave it to you.

If you want to display specific ads for specific manga, you can use this check to do it.

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

The above code will check if current reading manga ID is 100, chapter slug is “your-chapter-slug”. So you can combine the whole things to make your own advertising system.

Hope this help!

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

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

*

nineteen − four =