Add message into source file

Hello there!

How can I add a message to WordPress, which is visible only when to see page source? Many big companies have that thing, so when to see site's source, there is link to job offerings page. I tried adding text to index.php page, but it didn't seem to work.

For example, to see what I'm looking for, open up vox.com, view it's source and then you see a big message there.
Regards

  • Luís
    • Support

    Hi Andri ,

    Hope you're doing well today!

    It's using HTML comments, so, it's only visible in the source code:

    http://www.w3schools.com/html/html_comments.asp

    The easiest way is edit the theme header.php and add the comment right after the doctype declaration (<!DOCTYPE>:wink:.

    Other way, is add a function in the theme functions.php (or a mu-plugin) to be executed in wp_head with the max priority, like:

    function wpmu_source_code_comment (){
    
    	echo "<!-- My commnent -->";
    }
    
    add_action('wp_head', 'wpmu_source_code_comment',0);

    I hope this information has been helpful. If I can help you in this or other questions, please let me know!

    Cheers, Luís

  • Jude
    • DEV MAN

    Hey Andri

    You'd want to add this code

    function wpmu_source_code_comment (){
    
    	echo "<!-- My commnent -->";
    }
    
    add_action('wp_head', 'wpmu_source_code_comment',0);

    Place it in a mu-plugin. o create an mu-plugin, go to your /wp-content/ folder via FTP, and find the folder called "mu-plugins". If there is no folder with that name, then you'll want to create one. Then, create a file inside that folder, and give the file any name you like (making sure the file as an extension of .php, e.g. example.php) and paste the code in there.

    You don't need to activate that plugin, as it will be always be automatically activated. Please be sure to add a PHP start tag at the beginning of the code if you insert this code as a mu-plugin, like this:

    <?php

    Thank you for being a WPMU DEV member and have a fantastic day!

    Cheers
    Jude

  • andri333
    • Boss

    Jude hey

    Yeah, I have that folder and I will try that. There is few other things:

    1) So, the code inside the new php file would be like this?
    2) but I want to add there a bit more complicated message and I don't know how to copy it there the right way. The thing that I'd like to put there is this one

    I'm hoping that you can create a new code with that "art"-thingie, cause I'm really good at messing up everything that is code related :smiley:
    Regards

  • andri333
    • Boss

    Jude Hello

    What happened? - I spent 1 hour of my precious time to wait for your live chat session, but nothing :disappointed:

    Also, I made that new php file in mu-plugins folder, which includes that code, but can't see that message. Please go ahead and try to see that code when you view page source.
    (that last dot is also a link)

  • Dimitris
    • Support Star

    Hey there Andri,

    hope you're doing good and really appreciate your patience here! :slight_smile:

    Also, I made that new php file in mu-plugins folder, which includes that code, but can't see that message. Please go ahead and try to see that code when you view page source.
    (that last dot is also a link)

    As I can't spot any associated URL with this topic, could you please provide me the website you're trying to use this MU plugin? It would be awesome if you could grant us with support access too! :slight_smile:
    https://premium.wpmudev.org/manuals/wpmu-dev-dashboard-enabling-staff-login/

    Also, can you please confirm to me that the MU plugin is successfully activated? You can find a detailed manual about must-use plugins here https://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/

    Warm regards,
    Dimitris

  • Adam Czajczyk
    • Support Gorilla

    Hello Andri!

    I checked the source code of you site and it's minified. I can see that the Hummingbird minification is not enabled and WP Rocket is not set to minify files but it seems that you are using CloudFlare so I suppose that minification happens there.

    The way we're adding the "secret content" here is by putting a standard HTML comment into the page source code. All minification tools remove HTML comments from page source.

    Please go to your CloudFlare account and search for minification option. You should be able to disable this. Then you will want to clear WP Rocket cache on site and your browser's cache and check the source code again to see if these comments appear. That would confirm whether this is the issue or not.

    Best regards,
    Adam

  • andri333
    • Boss

    Hello, Adam!

    Good to have you back!

    I did both things you said, but didn't see any difference? Maybe you can see it? Disabling that Cloudflare minification made my site slow again :disappointed:
    I have also minfication option in my theme settings, as I remember.

    Kind regards

  • Adam Czajczyk
    • Support Gorilla

    Hello Andri!

    The site source still seems to be minified and the theme settings doesn't contain minification other than JS and CSS so it shouldn't affect clean HTML comments.

    Can you share the current code (entire) that you are using now with me? I'd like to double-check it.

    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.