• Hi. I’m trying to add a code snippet to the header using this plugin, but the code itself (window.suggestmeyes_loaded = true;) is displayed in the frontend when I’m logged in (but not for visitors).

    Here is the code:

    add_action( 'wp_head', function () { ?>
    
    	window.suggestmeyes_loaded = true;
    
    <?php } );

    I’m not a developper; so, I’m not sure if it is related to the plugin, the code syntax, or the theme. I’m using:

    WordPress version: 6.1.1
    Theme: GeneratePress 3.2.4
    Code Snippets plugin: 3.3.0

    Thank you very much.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hi @nobleknight,

    Can you please clarify: is this code being shown to only you, but you would like it to be shown to everyone?

    If this is the case, then it’s likely down to some caching software you have installed. Code Snippets performs no such authentication checks, and the snippet code does not appear to either.

    Thread Starter nobleknight

    (@nobleknight)

    Thanks, Shea, for your answer.

    After re-reading my request, I realize now that it was not enough clear and explained.

    Actually, what I want is that the code doesn’t show in the front-end.

    Unfortunately, after purging every cache I have, I found that code is displayed for everyone, not just me as an admin, which is definitely not the normal behavior.

    Moreover, the code breaks the website icon in the browser.

    If you think that the code is ok and the plugin won’t cause such thing, I think that it would be probably related to the theme or other plugins.

    • This reply was modified 1 year, 8 months ago by nobleknight.
    Plugin Author Shea Bunge

    (@bungeshea)

    Ah okay, that explains a lot. If you want code to only display for you as an admin, you can add a check with current_user_can to the beginning of the snippet:

    add_action( 'wp_head', function () {
    	if ( ! current_user_can( 'manage_options' ) ) {
    		return;
    	}
    	
    	?>
    
    	window.suggestmeyes_loaded = true;
    
    	<?php
    } );

    Additionally, as you appear to be writing JavaScript code, you might want to add some <script> tags:

    add_action( 'wp_head', function () {
    	if ( ! current_user_can( 'manage_options' ) ) {
    		return;
    	}
    
    	?>
    	<script>
    
    		window.suggestmeyes_loaded = true;
    
    	</script>
    	<?php
    } );
    Thread Starter nobleknight

    (@nobleknight)

    I didn’t even know that this code was a javascript. I intended to use it to solve some 404 issues in GSC, but I think I will search for other ways.

    By the way, I don’t want the code to show; neither for me as an admin or anyone, as it’s supposed to just be there for the bots/plugins causing the 404 error (a /undefined amended to the end of urls).

    Anyway, given that this was a javascript code and I’m using the free version of Code Snippets, I guess that won’t work. Thanks anyway for your effort and time.

    Plugin Author Shea Bunge

    (@bungeshea)

    The code I posted will work with both the free version of Code Snippets and with Code Snippets Pro.

    When I said ‘show’, I just meant it’ll be included on the page. It won’t actually be displayed on your site at all.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Code snippet in header is loaded in the frontend when I’m logged in’ is closed to new replies.