Possible to hook ads to the end of post?

Hi team,

I love the way this functions, with custom post types powering ads, ability to hook into categories and all sorts of great stuff and lots of flexibility.


I’d like to be able to hook this into the end of the post, rather than after x paragraphs or any other in-post modifier. Is there something I can add to functions.php or similar which will call the in post ad there, bypassing the “after x pararaphs” command?



  • indietravel
    • Design Lord, Child of Thor

    Hi tbennett04, thanks!

    I know it is possible to ‘do_something’ as the loop end, but what I’m wondering is what I need to be doing! What is the hook to grab, what will allow me to over-ride the positioning, without over-riding the category tie-ins?

    And, in addition (I guess), what will allow me to run that before any other plugins fire their end-loop stuff?

  • tbennett04
    • Site Builder, Child of Zeus

    @indietravel sorry I couldn’t find an easy way to do this within the plugin I think you could just do your own code. Something like this (sorry, totally untested but you get the idea):

    // get category of current post on single.php
    $category = get_the_category();
    $activeCategory = $category[0]->cat_id;

    // only show the ads on Posts
    if(get_post_type() == 'post'):
    $args = array(
    'post_type' => 'wdca_custom_ad',
    'posts_per_page' => 1,
    'tax_query' => array('wdca_ad_categories' => array( 'taxonomy' => $activeCategory))
    $post_ads = new WP_Query($args);

    // loop through the Post Ads

  • tbennett04
    • Site Builder, Child of Zeus

    Actually you would need to replace line #8 with the Post Type of the “In Post Ads”. Depending on how it was set up (if its using actual categories or not) you may need to replace line 10 with the Taxonomy instead of “cat”.

    edited post above ^^

  • tbennett04
    • Site Builder, Child of Zeus

    After line 19 you’d need to spit out the contents of the Post Ads, like the_title(), the_content(), or whatever the post ad post type uses. I’ll try to set it up and test it today if I can. Also make sure activeCategory is working.

  • Vladislav
    • Dead Eye Dev


    The latest plugin release (v1.4, just released) comes with a set of predefined positions (before, after and halfway through the post) in the plugin settings. You can now configure your plugin to use these injection positions, or to combine them with your selectors for injecting the ads.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.