Could you help with this?
I think I have all the correct code from various people it’s just how to check it’s optimised and then to actually execute it in the right place/way.
Basically what it should do is check for a logged in, currently paid-up subscriber and then NOT display MONUMETRIC ads for such people. Ie if you don’t subscribe you get ads.
- Working scenario
I believe that header.php is at the top of every wordpress blog post.
In my header.php file I have this line in red from my ad provider (MONUMETRIC) which works as-is and has done for months. I’m not sure if the synchronous execution is correct.
<?php wp_head(); ?>
… does nothing???
<script type="text/javascript" async="false" src="//monu.delivery/site/d/f/7accb3-ae6e-44dd-adf8-d5f3ea059f56.js" data-cfasync="false"></script>
- REPLACEMENT Code given to me by user subscription manager software company
function pmsc_enqueue_ads_script() {
if (is_user_logged_in()) {
$user_id = get_current_user_id();
if ($user_id != 0 && function_exists('pms_get_member_subscriptions')) {
$subscription = pms_get_member_subscriptions(array('user_id' => $user_id));
if (!empty($subscription) && (!empty($subscription[0]->expiration_date) && time() <= strtotime($subscription[0]->expiration_date)))
return;
else
wp_enqueue_script('ads-script', plugin_dir_url( __FILE__ ) . 'assets/js/script.js', array('jquery'));
}
} else {
wp_enqueue_script('ads-script', plugin_dir_url( __FILE__ ) . 'assets/js/script.js', array('jquery'));
return;
}
}
add_action( 'wp_enqueue_scripts', 'pmsc_enqueue_ads_script' );
- What I did 1 –
I disabled the existing script. <!script ……. <!/script>
- What I did (2)
I changed the ‘assets/js/script.js’ for =’//monu.delivery/site/d/f/7accb3-ae6e-44dd-adf8-d5f3ea059f56.js’
And then inserted the 12 or so lines of code exactly as shown
- What I did (3)
wordpress didn’t seem to like the function as shown above so I wrapped it in php brackets.
<?php
function pmsc...etc.etc.
?>
- What was shown:
After that code was inserted and caches cleared, the ads NEVER loaded. I tried it in an inprivate session with firefox and with IE11 both were logged out.
- So can you tell me why it’s not working at all? i guess i am including the script in the wrong way and making a really basic error. it’s a javacript script going into a php hader AFAIK
Many thanks !