Support » Plugin: Ad Inserter - Ad Manager & AdSense Ads » How to apply ad inserter filter in custom plugin

  • Resolved logii


    I am showing the $post->content in my plugin manually. I have tried doing this:

    $post = get_post(1234);
      print_r(apply_filters( 'the_content', $post->post_content ));

    $post->content still doesn’t have ad inserted into it. Perhaps I am missing something here? Please advice and thanks for the awesome plugin!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Spacetime


    The question is simple, but the answer is a little complicated.

    The plugins get called (including Ad Inserter), however, they insert code according to settings.
    In settings for Ad Inserter you define for each block where (on which pages) the code will be inserted.

    For example: if you set automatic display to “Before paragraph” and “For all posts”, then on all posts the code will be inserted before configured paragraph.

    To see if we are on the (single) post page, Ad Inserter uses is_single () WP function.

    And if you are executing your code on any other page that is not single post, the code will not be inserted.

    Try to execute your code on any single post and it should work.

    I have the same (urgent) request.
    Using an JSON API to feed my native mobile app, AdInserter is not inserting anything due to the is_single() check described above.

    Is there any way to work around this? Can I call the inserting feature manually without the check for the is_single()?

    $content = apply_filters( ‘the_content’, $post->post_content );
    $content_with_ads = call_ad_insert($content, nr_of_inserter);

    Would be VERY much appreciated!

    Plugin Author Spacetime


    Can you please describe where (on what pages) and how you would like to insert code with AdInserter?

    To insert code on post pages the is_single() check is mandatory to ensure the content parameter has post content.

    I would like to help you but need more information about your case.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to apply ad inserter filter in custom plugin’ is closed to new replies.