Tips and Tricks HQ Support Portal › Forums › WP eMember › WP eMember General Questions › WP eMember – Conditional Adsense
Tagged: adsense
- This topic has 6 replies, 2 voices, and was last updated 13 years, 7 months ago by derixc.
-
AuthorPosts
-
April 6, 2011 at 4:47 am #3123derixcMember
Hello.
I wanted to ask how can I exclude adsense code from my paying members. Basically I wanted to put the adsense code in the single post.php only for regular non-paying members. As for those paying members, I want the ads not to be displayed.
Is there a way to do this?
I have looked at this php code before but it only works by category filtering
<?php if ( !in_category(21) && !in_category(1) ) { ?>
“This is for the adsense code”
<?php } ?>
April 7, 2011 at 12:03 am #31108amin007ParticipantYou can find out if a member is logged in or not from eMember then show adsense code accordingly.
This page will help you with a code snippet to find out if a member is logged in or not:
http://www.tipsandtricks-hq.com/wordpress-membership/wp-emember-miscellaneous-tweaks-248
April 8, 2011 at 1:13 am #31109derixcMemberThanks for pointing this out to me, I have seen this page before but forgive me for not understanding on what to do with these codes. Is it something that I can simply copy and paste in the singlepost.php?
Is there a demo for this that i can look out as well?
April 8, 2011 at 8:46 am #31110amin007ParticipantOkay I have added another function in eMember that might make your job a little easier. It works similar to the “in_category()” example you gave me before. Get a new build of eMember from here:
https://support.tipsandtricks-hq.com/update-request
Now, you can use the following bit of code:
<?php if (!wp_emember_is_member_logged_in()){?>
"Adsense code goes here. This adsense is only visible to non logged-in visitors."
<?php } ?>Let me know if that helps.
April 9, 2011 at 1:40 am #31111derixcMemberFantastic.
I basically have two membership. Standard and Premium. From what I understand, the ads will be visible to all members, right?
Can I add a few extra code to strip the adsense out from premium users?
Hoping this is not too much to ask
April 10, 2011 at 1:47 am #31112amin007ParticipantNow you want more huh
Okay I modified that function a little so you can check against a particular membership level. In the following example ‘1’ is the membership level ID of your premium membership (modify 1 to whatever your premium membership level’s ID is).
<?php if (!wp_emember_is_member_logged_in('1')){?>
"Adsense code goes here. This adsense is only visible to someone who does not belong to membership level 1."
<?php } ?>You will need to get another build of eMember from here to get this new function:
April 11, 2011 at 12:48 am #31113derixcMemberyay. I never thought it will be granted. As always your support is awesome. Many many thanks.
-
AuthorPosts
- You must be logged in to reply to this topic.