Support » Plugin: Ad Inserter - WordPress Ads Management » How to apply ad inserter filter in custom plugin

  • Resolved logii

    (@logii)


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

    $post = get_post(1234);
      setup_postdata($post);
      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!

    https://wordpress.org/plugins/ad-inserter/

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

    (@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.

    Hi,
    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()?

    like:
    $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 Igor

    (@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.