I'd like to use Simple Ads or Pro Sites Ads to insert PHP code

I want to use Simple Ads or Pro Sites Ads but having trouble because I have to insert PHP code. Any suggestions on how I can do this?

Thanks

  • aristath

    Hello there @Tedster, I hope you're well today!

    You'd basically have to do some custom coding to get that...
    I have copied and modified the function from Pro-Site's ads module here so can can get an idea of what your code should look like.
    I haven't tested thi but it should work.

    add_filter( 'the_content', custom_advertising_output );
    function custom_advertising_output($content) {
    	global $psts, $ProSites_Module_Ads;
    	$ad_code = 'YOUR AD CONTENT HERE';
    
    	if ( $ProSites_Module_Ads->show_ads() && !is_feed() ) {
    		$per_page = $psts->get_setting('ads_count', 3);
    
    		if ( is_page() ) {
    			if ( $psts->get_setting('ads_before_page') ) {
    				if ( $ProSites_Module_Ads->ad_counter < $per_page ) {
    					$content = $ad_code . $content;
    					$ProSites_Module_Ads->ad_counter++;
    				}
    			}
    			if ( $psts->get_setting('ads_after_page') ) {
    				if ( $ProSites_Module_Ads->ad_counter < $per_page ) {
    					$content = $content . $ad_code;
    					$ProSites_Module_Ads->ad_counter++;
    				}
    			}
    		} else {
    
    			if ( $psts->get_setting('ads_before_post') ) {
    				if ( $ProSites_Module_Ads->ad_counter < $per_page ) {
    					$content = $ad_code . $content;
    					$ProSites_Module_Ads->ad_counter++;
    				}
    			}
    			if ( $psts->get_setting('ads_after_post') ) {
    				if ( $ProSites_Module_Ads->ad_counter < $per_page ) {
    					$content = $content . $ad_code;
    					$ProSites_Module_Ads->ad_counter++;
    				}
    			}
    		}
    	}
    	return $content;
    }

    You can add that in your theme's functions.php file and modify it to your needs.

    I hope that helps!

    Cheers,
    Ari.

  • Tedster

    Thanks for the replies, and sorry I didn't get back to this sooner... I was off line for a little while.

    While I was off line I had some time to write a simple plugin (my very first, yay!) to do the trick. Basically, it just echos out the PHP I need at the end of single posts.

    Jack, I can't share the code because it's dependent on phpBay API, a proprietary script from phpbay.com. But really, anything that echos hello world would do the trick, replacing echo ('hello world'); with the PHP one wishes to use.

    Ari, thanks for the code. While I did make my little plugin to do what's needed, I will still pick apart the code you provided to further my learning. As it stands, my plugin works for posts but not for pages. That's my next step and your code will help me work that out.

    Thanks again!