There are four methods of the outputting of ads.
- Automatic embedding into the site content
- Widgets
- WordPress Shortcodes
- Using functions
Automatic Embedding
This method is described in detail in the section “Settings”.
Widgets
To display ads in any sidebar you can use the widgets of the SAM Pro Free plugin. There are four widgets – Ad, Place, Zone and Block. Just drop any of these widgets to the sidebar you need and adjust it.
Title – title of widget if needed.
Ad, Place, Zone, Block – select the necessary ad object.
You can hide widget style (usually for the header widgets) and allow using predefined tags (Place, Zone).
WordPress Shortcodes
Click “Insert Advertisement” toolbar button, in opened dialog select necessary Ad Object and click “Insert” button. If necessary, check the box “Allow predefined tags”.
If you want insert shortcode manually use following code:
Where the first digit in the id is:
- 0: Place
- 1: Ad
- 2: Zone
- 3: Block
The second digit is id of the Ad Object.
Also you can use shortcodes in the WPtouch Pro Multi-Ads addon.
Using functions
Traditional
In order that would insert an Ad Object in any place of theme template, use the samProDrawAd, samProDrawPlace, samProDrawZone or samProDrawBlock functions.
Output functions are defined as follows:
1 2 3 4 |
function samProDrawAd( $id, $args, $useTags ) function samProDrawPlace( $id, $args, $useTags) function samProDrawZone( $id, $args, $useTags ) function samProDrawBlock( $id, $args ) |
- id – Ad Object id
- args – array, which may include the wrapping tags (before and after parts of tags)
- useTags – allow wrapping tags
Using Functions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// Place output if(function_exists('samProDrawPlace')) samProDrawPlace( 1, null, true ); // or if(function_exists('samProDrawPlace')) samProDrawPlace( 1, array('before' => '<div class="ad">', 'after' => '</div>'), true ); // Zone output if(function_exists('samProDrawZone')) samProDrawZone( 1, null, true); // or if(function_exists('samProDrawZone')) samProDrawZone( 1, array('before' => '<div class="ad">', 'after' => '</div>'), true ); // Single Ad output if(function_exists('samProDrawAd')) samProDrawAd( 1, null, false ); // or if(function_exists('samProDrawAd')) samProDrawAd( 1, array('before' => '<div class="ad">', 'after' => '</div>') ); // Block output if(function_exists('samProDrawBlock')) samProDrawBlock( 1, null ); |
Alternative
From version 2.0.0.75 you can use more flexible alternative of outputting ads. Using this method you can obtain an Ad Object and use its data as you need. For example for defining objects of Google Analitics.
For that you should use public methods getAd , getPlace , getZone and getBlock of $samProObject , it is the global instance of the main plugin’s object.
Returned object contains next public data:
- ad – HTML tags of current ad
- width – the width of ad
- height – the height of ad
- aid – ID of current ad
- pid – ID of Place (this data is not available for object returned by getAd method)
- adName – the name of ad
- eid – ID of the HTML element of ad
Using Methods:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
// Getting Ad function getMyAd() { global $samProObject; $ad = $samProObject->getAd( 1, null, false ); return $ad; } $myAd = getMyAd(); echo $myAd->ad; // Getting Place function getMyPlace() { global $samProObject; $ad = $samProObject->getPlace( 1, null, false ); return $ad; } $myPlace = getMyPlace(); echo $myPlace->ad; // Getting Zone function getMyZone() { global $samProObject; $ad = $samProObject->getZone( 1, null, false ); return $ad; } $myZone = getMyZone(); echo $myZone->ad; // Getting Block function getMyBlock() { global $samProObject; $ad = $samProObject->getBlock( 1, null ); return $ad; } $myBlock = getMyBlock(); echo $myBlock->ad; |
Disabling Ad Serving
You can disable ad serving on any post or page of your blog.
Just turn on “disable ad serving” checkbox. Ads will not be shown in this article or on this page.
© 2015 – 2017, minimus. All rights reserved.
Hey SAM,
I am using SAM PRO wordpress pluging in my dev environment website . but ads rotation/ scheduling is not working. means ads are not expiring after their time out. please gives us the right solution , what i am mission in scheduling ?
You’ve enabled the rule of schedule on the Settings page?
Hi, having the same issue, everything is set up correctly, and using {php}samProDrawPlace( 5, null, true );{/php} to output.
With this, I still see the ads that are in the trash, and the ones that are out of scheduling. That is not supposed to happen. All the settings are correctly checked.
Same behevior if I do {php}do_shortcode(“
“){/php}
But it seem to work with the widgets….
Wait for the next version … I think I found a bug.
Weirdly, now that I have updated to WordPress 4.4, it seems to work. Don’t know why…
Or maybe because I deleted the earlier sam plugin…
Maybe…
Hi, I am using SAM Pro Free, I have 3 places on a post top, widget and bottom. I want to have 3 adverts that are from 1 campaign on the page at the same time. Example: 3 ads regarding apples at the same time on the same page, then i refresh and there will be 3 ads regarding oranges at the same time on the same page. Is this possible? I cant find any option for this. I tried weight but i don’t think this is correct. And there is no documentation on this option that i can find. Please help.
This is not possible. Different Places do not depend on each other.
yes, sure i’ve done it, yet this is not able to expire the ads.
Read reply on WordPress.org forum…
When attempting to get a shortcode, I always get a -1 as the response, with no shortcode. Thoughts?
Hello SAM,
I am using SAM (old version) without activating the stats. Hostgator has blocked my 4 sites (.com) on a shared hosting plan due to cpu overloading. I should delete the plugin to avoid blocking of my sites and use WP Super Cache instead of running the more cpu consuming W3total cache. Would the change to SAM pro free with wp super cache solve these kind of problem and which settings shall I activate? I have about 1 million visitors a month on my sites.
Thank you very much for your recommendations.
Yes!
1. The new plugin requires significantly fewer resources for the collection and storage of statistical data.
2. You should select javascript output mode to compatibility with any caching plugin (including WP Super Cache).
Thanks a lot for the very fast answer, SAM!
If I switch to SAM Pro Free do I have to deactivate the SAM Plugin before installing the new one or should I install the new SAM first without deactivating the old one go to tools of the new one starting the migration process according to //uncle-sam.info/sam-pro-free/sam-pro-free-docs/tools-2/ and deactivate and delete the old one then. I don’t like to loose my ads and all the settings in the changing process. I haven’t found a step by step instruction to make sure that I don’t loose my ads. I would appreciate your instructions.
Read this article…
Are we able to still use ‘Customizable limitation of displaying advertisements on single post page or author archive page by author’ as we were with Simple Ads Manager.
Yes, but you should turn on the necessary rules on Settings page at first.
Hello,
I’m using Sam Pro(Free Version) for showing ads and I used the shortcode method. Assume I have place with id 24 which contains three ads. Now I want to display those three ads by the place id in front end. I wrote the code echo do_shortcode(““) in my template file but it is displaying only one ad at a time. Can you please tell me what is the way to display multiple ads contained within a place ?
Thank you..
If you want to show 3 ads as a grid of ads you should use the Block object. If you want to rotate ads by time intervals you should use SAM Pro (Lite Edition) plugin.
The better code is:
[php]if(function_exists(‘samProDrawPlace’)) samProDrawPlace( 24, null, true );[/php]
Hi fantastic plugin – only thing that does not work for me is the geotargeting thing. I have chosen dp ip as provider entered the api key and followed all the rules in the docs. The region database is populated and i can select country & state. I just doesnot work eg if i exclude my home country – ads still show up. Made several trials with international checks. Tried on a different install – same effect. Anything that needs to be done server-side or any other idea. Site test url is kalender-2016.de/kalender-2016-bayern-t/.
Thanks for a quick response.
Hi! Thanks!
The one part of concept is: if you show single ad, you want to show it without restrictions. You should show ad as part of Place if you want to use restrictions. Create new Place and link your ad to this Place. All rules defined for ad will work.
Hi Minimus,
thanks for your very quick response. I followed your instruction and now it works if the ad is linked to a place and it is embedded on the site.
It works fine on the country based targeting but not regional ( checked with my VPN client ). I thought that could be because of incurracy of DB-IP data so I signed up and bought service from MaxMind GeoIP2 precision (50.000 queries). I have entered the User ID and License key as required in the geolocation source dashboard and this is what I get:
Fatal error: Call to undefined function console() in /var/www/web831/html/k17/wp-content/plugins/sam-pro-lite/tools/maxmind-client-2.php on line 61
Can you please quickly help
Thanks
christoph
I’m terribly sorry! It’s my mistake. I forgot remove the debug functions from the file
mixmind-client-2.php
. Open this file (sam-pro-lite/tools/mixmind-client-2.php
) and remove lines 61, 62, 63.Thanks for your quick support – no error messages anymore. it´s strange however that country exclusion works with DP-IP but not with Mindmax (with exactly same settings – just changed the geotagging source, tested with geopeeker).
Christoph
I have not MaxMind account and I developed this part of plugin using MaxMind documentation only. Can you send me the response data structure of MaxMind service. Maybe it has some changes…
The bug found.
Open file
maxmind-client-2.php
and find code:[php]else $out = array(
‘address’ => $this->addr,
‘iso1’ => $response->country->iso_code,
‘country’ => $response->country->names->en,
‘iso2’ => $response->subdivisions->iso_code,
‘region’ => $response->subdivisions->names->en,
‘city’ => $response->city->names->en
);[/php]
and change it to:
[php]else $out = array(
‘address’ => $this->addr,
‘iso1’ => $response->country->iso_code,
‘country’ => $response->country->names->en,
‘iso2’ => $response->subdivisions[0]->iso_code,
‘region’ => $response->subdivisions[0]->names->en,
‘city’ => $response->city->names->en
);[/php]
Hi! I’m using SAM Pro Free to display ads on a site but due to some special requests of the website owner I need to print ads using functions and wrapping tags. I’ve copied your example (btw, in the exaple there isn’t third parameter, I’ve passed true) but the plugin doesn’t print before and after that I’ve chosen, so I’ve checked your files and… it seems that the constructor of the ad take the args but don’t use them! There is no “if ($before) print…”!
Is it a pro feature and is it written here in the free documentation by mistake? Or simply did you forget to use them?
Thanks!
The wrapping tags are using only by the Place and are handling by the Place. The tags parameter exists only for the future use and for compatibility with Full version of the plugin.
Thanks for your answer.
My problem remains… I need to wrap the ad in some div class=… but the function echo the ad instead of returning it, so if I print the div either in my function.php or in the widget, the result will be the ad printed before my divs.
Can you make a function that return the ad insted of printing it? Thank you so much for you interesting!
I’ve solved the problem simply adding this simple line of code at the end of sam-pro-ad.php before the return:
[php]if ($this->useTags && $this->before && $this->after)
$out = $this->before.$out.$this->after;[/php]
but is an hack, so it’s impossible for me to update the plugin without hacking it every time.
Hi,
I would love if this worked!
Using the latest wp version I disable the ads and they still display (even when added to trash), the active/inactive does not stop the ad from displaying, the page placement – location (what pages to display on , etc.) don’t work either.
The widget worked but those pages showed the same add twice since the ad shows everywhere unless I check the page to disable the ad server or unless I disable the plugin.
So the ads show up unless 1. I disable the plugin or 2. I disable the ad server, I tried everything else except disabling the other plugins.
Wondering if another plugin is causing conflict ( i have a widget placement plugin “Display Widgets”). Any suggestions would be appreciated.
thanks
If you use caching, you should flush cache.
I can’t find much information about how the “weight” field works. What is the range of numbers I can put in the field? If I enter an ad’s weight as “3”, does that mean it gets shown 3 times as often as an ad with weight of “1”? What are the numbers I have to enter in that field to make sure an ad appears more often than others?
Yes, you are right. The value of the ad weight can be from 0 to 10 (0 – not displaying , 10 – maximum shows of an ad). Use “10” value to show some ad more than another ads. Set weight for other ads lower than “10”.
Thank you for your reply! If I may make a suggestion, I think it would be a better user experience if the weight input would not allow a number higher than 10. For example, my colleague was entering numbers like 75 or 99 and getting confused that it appeared his ads weren’t weighting the way he thought they would.
Even putting a little more instruction in the field’s label or in the documentation would be helpful, something like “1-10, higher numbers have higher weight and will be shown more often.”
Thanks again!
We are calling Ad through function call in the frontend. How do check Schedule start and end time. Based on this, i need to display.
Please help me!
Turn on needed rules on the plugin settings page (section Rules)…
HI
Please i had a problem with SAM, i have an ad that show an especific category, but doesn’t work, just i wanna know if can i send the category to show and display that ad just for that category.
Thanks
Yes, of course! Just turn on certain rules on the plugin settings page…
I’m hoping you can help me. We recently switched our WordPress database’s table prefix (for security reasons). We changed every table name and ran a search-and-replace on all instances within the database.
Now I’ve got the site back up. I’m able to see all of my ads in the backend of WordPress, but for some reason they’re not appearing on the frontend. Could this be a result of the table prefix renaming? And if so do you know how I could resolve this issue?
I’m using SAM Pro (Free) Version 1.9.6.67, WordPress 4.6.1
Never mind, I solved the issue. Turns out there were a couple foreign key constraints that I forgot to change over. I cleared all settings and data from the plugin, reloaded the SQL database information and now I’m back up and running.
Ok! Very good!
Hi minimus,
I´ve written a function that inserts the ad place after more-break in wordpress. I´ve the problem, that the ad place is drawn before the more break.
I think I could solve it when I use this:
[php]function insertad() {
$test = if(function_exists(‘samProDrawPlace’)) samProDrawPlace( 1, null, true );
return $test;
}[/php]
But it doesn´t work. Isn´t it possible to save the return of this function in a variable?
Hope you can help me.
Thanks
dortcom
This is the code of the function {php}samProDrawPlace{/php}:
[php]function samProDrawPlace( $id, $args, $useTags ) {
global $samProObject;
if ( is_object( $samProObject ) && ! is_admin() ) {
$ad = $samProObject->buildPlace( $id, $args, $useTags );
echo $ad;
}
}[/php]
I think you can write the code you need using this example.
Hi minimus,
thank you very much.
This function works for me:
[php]function my_ad() {
global $samProObject;
$ad = $samProObject->buildPlace( 1, null, true);
return $ad;
}[/php]
Thanks
Sven
Hi, thank you for this great plugin.
I am using the samProDrawPlace function but wondered is there a function I can use to query the title and description of the ad that is returned?
I want to pass the ad name to Google Analytics Tag Manager as an extra data layer.
Hi!
You can’t obtain ad name using
samProDrawPlace
function.To my mind this is useful feature and I’ll add it into the next version of plugin.
Regards!
Ready! Try it!
Awesome! Thank you so much!
Hey minimus,
We started using a host with server-side caching, and for some reason when caching is turned on, none of the ads are being served. They’ve excluded the wp-content folder from caching, and the ad output mode is set to “Caching Compatible (JavaScript)”, so it’s not entirely clear what the issue is.
To display the ads, we are using the SAM Pro Place widget items.
Could you share the path used to request these ads? According to our hosting “What’s happening is that we’re able to exclude the assets SAM Pro pulls, but not the request Sam Pro makes, and it’s the request itself that’s displaying cached content.“. Or maybe there is another setting that I should try that I’m not taking into account…
Thanks!
I setup Sam Pro Ads on my site but no matter what I do, I can not get the stats to email out. I get an error An error has occured. Mail not sent.
I click the advertiser it highlights then I click the mail icon and it will not send.
Is it possible to set up an ad Block that displays three identically sized ads, all linked to the same group of ads, but prevents duplicating the same ad on multiple places? Does that make sense?
I tried doing this by creating a Block of 3 ads, and then choosing the same Place for each of the three. The result was all three ads showing the same thing. Please let me know. Thanks!
Hi,
The drop down menu does not show any Ads object. Is there any one to fix that?
Thanks.
Turn off AdBlocker…
I can’t seem to find on this site where you describe the differences between ads, places, blocks, and zones. (I know it’s here; I just can’t find it!) I want to rotate a block of two ads (120×600 skyscraper and 160×600 skyscraper) with a single ad (300×600 skyscraper), but I can’t figure out how I need to set that up to be able to display both options.
Hi there –
I’ve got an issue with using an Ad Place in a footer area on my site. I’m able to use the widget to place a single ad, but I’m unable to get any ads to appear when I use the Place widget. I’ve attempted to use custom html widget and place a shortcode in it, but that didn’t work either. Can you offer any insight?
Thank you!
Hi! Are you add necessary ads into Ad Place?
Got a recent issue. Running SAM Pro Lite. Just added a new ad and now that’s the only one that shows up in the Places. Even though there are several other ads in that place. Any ideas? Thanks.