{"id":2754,"date":"2023-03-18T21:43:32","date_gmt":"2023-03-18T16:13:32","guid":{"rendered":"https:\/\/nigeljoy.me\/?p=2754"},"modified":"2023-03-18T21:56:48","modified_gmt":"2023-03-18T16:26:48","slug":"avoid-showing-author-name-discord-link-preview","status":"publish","type":"post","link":"https:\/\/nigeljoy.me\/avoid-showing-author-name-discord-link-preview\/","title":{"rendered":"How to Hide Author Name When Sharing Your Site in Discord"},"content":{"rendered":"\n

Are you looking to customize the link preview shown in Discord for your WordPress site? Do you also find it annoying that Discord gives more visibility to the author name instead of site title in the link preview? Well, look no further. I have the solution for you. In this article, I will show you how to customize your WordPress site to hide the author name from link previews in Discord.<\/p>\n\n\n\n

The Problem with Link Preview in Discord<\/h2>\n\n\n\n

The information link preview shown in social media sites like Facebook, Twitter are taken from Open Graph tags of the site that is being shared. It is a set of tags in the source of the webpage that shows information like page title, page description, featured image, etc which are used to generate media rich preview of the website in the feed of the social media site. <\/p>\n\n\n\n

Discord doesn’t rely on Open Graph tags, instead, it uses something very similar – the oEmbed data to create a rich preview of the shared link. Unfortunately, Discord has a pretty odd looking preview where the author name has more prominence than everything else in the preview. Just take a look at the screenshot of link preview generated in Discord for my website in Discord..<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

In the first line, you can see the name of my website – “Nigel”, which for some reason has a very tiny font size. In the second line, what you are looking at is author of that page – “Nigel” which for some reason is highlighted in white and is more prominent.<\/p>\n\n\n\n

In my opinion, the link preview in Discord lacks a proper structure. I also do not think it is useful to expose author name on link previews, especially for personal blogs. Moreover, I think Discord could take a lesson or two from Twitter and Facebook to create a better looking preview with proper hierarchy for the information that is displayed.<\/p>\n\n\n\n

Since Discord relies on oEmbed, it will still show the author name even if the author name is not explicitly exposed anywhere on the webpage or in its source code. This can be concerning for privacy conscious bloggers and website owners. <\/p>\n\n\n\n

In my case, I just do not find it nice to have my name repeated twice unnecessarily for the link preview of my personal site.<\/p>\n\n\n\n

The Solution to Hide Author Name in Discord Link Preview<\/h2>\n\n\n\n

While Discord could do something about making their link preview better or hide the author name, it is easier said than done. The best you can do is to make the necessary changes on your site to prevent exposing the author name.<\/p>\n\n\n\n

To do this, you will need to add a custom PHP code to modify the oEmbed output generated by your WordPress site. Follow the steps below:<\/p>\n\n\n\n

1. Install a Code Snippet plugin to your WordPress site. I recommend WP Code<\/a>. However, you can find other similar plugins here<\/a>. <\/p>\n\n\n\n

2. Once WP Code plugin is activated, go to Code Snippets > Add Snippet > create your own.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

3. Give a title for the snippet and select “PHP Snippet” for the Code Type.<\/p>\n\n\n\n

4. Paste the following code:<\/p>\n\n\n\n

add_filter( 'oembed_response_data', 'hide_author_filter_oembed_response_data_' );\nfunction hide_author_filter_oembed_response_data_( $data ) {\n    unset($data['author_url']);\n    unset($data['author_name']);\n    return $data;\n}<\/code><\/pre>\n\n\n\n

5. Set Location to Location to “Frontend Only”. <\/p>\n\n\n\n

6. Save the snippet and Activate it.<\/p>\n\n\n\n

\n