acceleratedconversions
Forum Replies Created
-
Thanks @danieliser I think that did it!
Forum: Fixing WordPress
In reply to: Update Footer.php to Load Content for Non-Admins OnlyOkay I got it to work, but I’m not exactly sure which of the things I did fixed it. First, the final, working code:
<?php if( current_user_can('manage_options') ) : //Block Active Admins from Submitting Analytics Data ?> <!-- No GA --> <?php else : ?> <!-- Show GA --> <?php if( of_get_option('analytics_code') != "" ) : ?> <?php echo of_get_option('analytics_code'); ?> <?php endif; ?> <?php endif; ?>
1) My best guess about what was wrong with the original code is that in the Codex for current_user_can() the original code I used had “Level_10” which is deprecated. I revised that to say current_user_can(‘manage_options’) — which means admin privileges.
2) I removed the first if statement that checked for a user ID, since I thought perhaps this was unnecessary.
3) I was suspicious that there were caching issues causing an older (local) version of the footer.php file or page to load. Sure enough, I tried adding version numbers to the comments while I was troubleshooting and often when I published the new footer.php the previous version still showed up until I cleared out my cache. So perhaps one of the examples you supplied (or even my original code) would have worked, but because of caching it was never executed by the browser.
4) While this doesn’t have any impact on the code’s functionality, I wound up moving the comment about the code removing Analytics for admins from the “<!–” syntax placed outside of the PHP code to the “//” syntax within the PHP. I just didn’t want the comment about removing Analytics for admins to show up on my page even if the Analytics code didn’t load.
Thanks for your help!!
Forum: Fixing WordPress
In reply to: Update Footer.php to Load Content for Non-Admins OnlyAlen: I tried what you suggested, but it wound up implementing the analytics code for the admin account, which is the opposite of what I was looking to do.
Stephen: The original code I posted used current_user_can. I tried the suggestion you made (but reversed the order, since I wanted the Analytics Code for everyone <i>except</i> the administrators) and got this:
<!-- Block Active Admins from Submitting Analytics Data --> <?php if ( current_user_can( 'administrator' ) ) : ?> <!-- No GA --> <?php else : ?> <!-- Show GA --> <?php if( of_get_option('analytics_code') != "" ) : ?> <?php echo of_get_option('analytics_code'); ?> <?php endif; ?> <?php endif; ?>
However I still have the same symptom. The condition for the admin worked, but it didn’t for the non-admins.
Forum: Fixing WordPress
In reply to: Update Footer.php to Load Content for Non-Admins OnlyI tried this:
<!-- Block Active Admins from Submitting Analytics Data --> <?php if( is_admin() ) : ?> <!-- No GA --> <?php else : ?> <!-- Show GA --> <?php if( of_get_option('analytics_code') != "" ) : ?> <?php echo of_get_option('analytics_code'); ?> <?php endif; ?> <?php endif; ?>
And now when I view source I see the non-admin code (Google Analytics) even when I’m logged in. Since the link you sent says is_admin() checks to see if the “Dashboard or the administration panel” is trying to be displayed, I also tried making sure that I turned on the tool bar at the top of the screen when I visit my page, since I normally don’t have that on. That didn’t work either though.
Perhaps I should have clarified, I’m looking to block my own traffic to the public-facing parts of my site (https://acceleratedconversions.com), so I want this script to load in the footer.php file for all of the pages on my site, not just on the admin section.
Not a problem, Ryan! Thanks again.
Thanks so much Ryan, this is exactly the kind of solution I was looking for. It worked perfectly, as you can see on my site.
For anyone who finds this thread later, I was able to change the success message based on the instructions in this support topic.