This weekend I was having some difficulty inserting ads within the middle of a post using the plugin  Simple Ads Manager.  In retrospect (cutting to the chase a bit) there seems to be a setting within the Ads place setting that has the power of turning this on or off.  I’ve stumbled on it by accident twice, but not able to replicate the process when I need it.
I like the plugin for managing ads in other areas of a WordPress install, just fine.  Its the insertion within a post (ergo maybe 3-5 paragraphs down or something) where it gave me trouble.
So I tried to tackle things in a semi old school way.  A quick Google search put me on the refresher course for inserting ads, in this example Adsense ads in a post.  An article titled Adding Adsense within the Post Content – WordPress & Genesis helped quite a bit, however, I definitely did not want to follow this method on my own site.
In my case I am running a StudioPress Child theme and Genesis Framework.  The code in that example provides for the creation of essentially a ‘plugin’ but one in the theme file, ergo something that hooks into the theme and alters the output.
I was already running Simple Hooks for Genesis Framework so it did not make sense to create a file to do that all over again.  I just needed to find the Simple Hooks way of achieving the same result.
But I didn’t want to insert raw code, I wanted to call ads managed by the plugin Simple Ads.  I don’t want someone working for me to have to go alter code that might potentially break the theme everytime they need to put a new ad in to rotation!
So I first went into Simple Hooks, navigated down to the Post/Page Hooks section  and added the following code to the genesis_post_content Hook:
[sam id=5 codes='true']

';
$content = apply_filters('the_content', get_the_content());
$content = explode("
", $content);
for ($i = 0; $i <count($content); $i++ ) {
if ($i == $paragraphAfter)
echo $ad;
echo $content[$i] . "
";
}
?>

Here’s the image if that code insert is broken
inserting-ads-mid-content-genesis-theme
I also checked the box – Unhook genesis_do_post_content() function from this hook?
and then checked the box to allow both shortcodes and php to execute on this item as well.
the short code within the php above is from the Simple Ads Manager (SAM) and it is calling the 5th ads place set of ads that rotate and telling it to display here.
I seperately created a div and class to style the ads such that they would float right with some amount of padding in the content. I later added some css to a custom style sheet to achieve the result I was looking for: .adsensefloat {
float: right; padding: 30px;}
I’m still testing to understand the unintended consequences within Simple Ads Manager, but it seems to stem from a check box option in the Ads Places setup after you select html and then see a check box for “This is one-block code of third-party AdServer rotator. Selecting this checkbox prevents displaying contained ads. This is a HTML-code patch of advertising space. For example: use the code to display AdSense advertisement.”
This seems to sometimes turn on the insertion of ads within the content, but not always…
If you’ve had experience with this, I’d love to compare notes!

Pin It on Pinterest

Share This