• marchenko.alexandr

    (@marchenkoalexandr)


    So if You want to add your ads into post body, all you need is add following code to wp-content/plugins/datafeedr-ads/datafeedr-ads.php

    function datafeedr_ads_filter($content) {
    	preg_match_all('/\[ad-([^\]]+)\]/six', $content, $matches);
    
    	if(!empty($matches)) {
    		$codes = $matches[0];
    		$ids = $matches[1];
    
    		for($i = 0; $i < count($codes); $i++) {
    			$code = $codes[$i];
    			$id = $ids[$i];
    			$ad = '';
    			if (function_exists('dfrads')) {
    				$ad = dfrads($id);
    			}
    			$content = str_replace($code, $ad, $content);
    		}
    
    		return $content;
    	}
    
    	return $content;
    }
    add_filter('the_content', 'datafeedr_ads_filter');

    And now anywhere in post content you may add code like following:

    [ad-4298077]

    where 2346323 copy pasted from Template code: <?php if (function_exists('dfrads')) { echo dfrads('4298077'); } ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • I try this method and every time I get a message saying the add does not exist? I wonder why?

    I try it and get nothing showing at all. Any tips?

    Thread Starter marchenko.alexandr

    (@marchenkoalexandr)

    First of all u need to check is filter working at all. For this try change return lines from:

    return $content;

    to something like:

    return "Hello world $content";

    And refresh your page. If u will see “Hello world” at start – all ok, filter works fine.

    Then u may check is dfrads function actualy exists, change code:

    if (function_exists('dfrads')) {
    	$ad = dfrads($id);
    }

    to:

    if (function_exists('dfrads')) {
    	$ad = dfrads($id);
    } else return "FUNCTION DOES NOT EXISTS";

    And again refresh page, if function exists nothing will happen, otherwise u will see the message.

    And last one, if filter works, and function exists there is probably problems with regex, or maybe you are entering wrong id for ad.

    Thank you I got this method working, however is there a way to show all of your ads on a page, rather than just displaying one at a time?

    Thread Starter marchenko.alexandr

    (@marchenkoalexandr)

    probably u can not do this with this plugin – as i remember it works that way – so u can show only one banner at a time

    if u want more specific system and dont wan programm anything probably you should use something like google.com/dfp

    Just installed the code from the first post. Works perfectly.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Random / Rotating Ads V2] Ads in post content’ is closed to new replies.