Discover in this tutorial how to verify your WordPress websites on Mastodon with a little bit of code.
Mastodon is a social network that has gained a lot of traction due to the uncertain times that Twitter is going through, at least at the time of publication of this tutorial.
One of the advantages this federated social network has is that you can verify yourself if you are the legitimate owner of a web page.
This is shown in the user profile:
Let’s see how to do it.
Snippet to verify your WordPress website on Mastodon
First of all, you have to know the URL of your Mastodon profile. In fact, if you go to edit it, you get a section that allows you to copy the HTML and even gives the instructions:
You can verify yourself as the owner of the links in your profile metadata. For that, the linked website must contain a link back to your Mastodon profile. The link back must have a rel=”me” attribute. The text content of the link does not matter. Here is an example:
And that’s precisely what you’re going to do with the following snippet that you can add to your functionality plugin:
// Add Mastodon verification
add_action('wp_head', 'cg_add_mastodon_verification');
function cg_add_mastodon_verification(){
if( is_front_page() ){
echo '<a rel="me" href="https://mastodon.social/@nahuai"></a>';
}
}
With this snippet you add the necessary HTML markup in the header of the main page(is_front_page()
).
You can make sure that the HTML has been added correctly by checking the header from the web inspector. You should see something similar to this:
You can modify just the URL or replace the entire HTML(
) with the one you copied from your Mastodon profile.
Conclusions
Have you created a Mastodon account and want to show your WordPress websites as verified? Now you know how to do it with a little bit of code.
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂