• I am trying to display ads on my WP blog. But I want to exclude some posts and display the ad on certain posts. I assume you can hack the function.php to achieve that, but I have no idea in terms of the actual code. I would appreciate any help. Thanks in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You would need to use any of the available WP Cnditionals to test which page is being viewed.

    So, for example, if you only wanted to display ads on the homepage:

    function my_display_home_ad() {
        if is_home() {
            // Run your ad code here.
        }
    }

    Then, you will need to hook this function to the content or an available hook in your theme. Like so:

    add_filter('the_content', 'my_display_home_ad');

    Even better… try it like this:

    if is_home() {
        function my_display_home_ad() {
            // Run your ad code here.
        }
        add_filter('the_content', 'my_display_home_ad');
    }

    This way… it will only execute the function on the home page. Rather than executing the function on every page, and then finding out it never needed to execute the function in the first place.

    exclude some posts and display the ad on certain posts

    how and where do you want to define ‘some’ and ‘certain’?

    Thread Starter satrap

    (@satrap)

    Josh and alchymyth, thanks to both of you guys for taking time to help out.

    “how and where do you want to define ‘some’ and ‘certain’?”

    Thats the problem I have. I know there are a few ways to do that like by category or tags. But I only have one category and I don’t use tags, so I can not use that in the code to identify the posts and pages that can display the ad.

    The only way I assume it could be achieved is using the post ID to exclude or include .

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How do you display an ad on certain posts?’ is closed to new replies.