Webtiryaki Bulut Themes!

The simplest and fastest way to build great UI for your community.

Show only if user-role is subscriber AND site visitor (Wordpress)

  • Thread starter Thread starter Huxtable
  • Start date Start date
H

Huxtable

Guest
I am a bit stuck with the code below for my Wordpress site:

Code:
<?php
    $user = wp_get_current_user();
    $allowed_roles = array('subscriber', 'visitor');
     if ( array_intersect($allowed_roles, $user->roles ) ) echo '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXXXXXXXXXX" crossorigin="anonymous"></script>' ?>

I want the Adsense code only be shown in the HEAD section for site visitors and the user role SUBSCRIBER. I tried 'visitor' but that didn't worked.

I don't know how to apply "array_diff" in this situation to display the Adsense code in the header for SITE VISITORS and SUBSCRIBER role?
<p>I am a bit stuck with the code below for my Wordpress site:</p>
<pre><code><?php
$user = wp_get_current_user();
$allowed_roles = array('subscriber', 'visitor');
if ( array_intersect($allowed_roles, $user->roles ) ) echo '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXXXXXXXXXX" crossorigin="anonymous"></script>' ?>
</code></pre>
<p>I want the Adsense code only be shown in the HEAD section for site visitors and the user role SUBSCRIBER. I tried 'visitor' but that didn't worked.</p>
<p>I don't know how to apply "array_diff" in this situation to display the Adsense code in the header for SITE VISITORS and SUBSCRIBER role?</p>
Continue reading...
 
Top