ReactJS: How can I change the link preview of a URL? - javascript

I don't know where to start with this, my default link preview for my site looks like this:
I don't know why it's displaying bootstrap and not what is in my site. This is the page I am trying to share:
so I was expecting that the link would have the image and the title(blacked out).
But on the good side, when you click on the bootstrap link, it will redirect to my page and not to bootstrap but still what I cannot get is why is it displaying bootstrap and not what is on the page? Where can I change it?
Thanks for the help.

Your problem is this line in your <head>:
<link rel="canonical" href="https://getbootstrap.com/docs/4.0/examples/blog/">
This tells bots, web crawlers, and generally everyone that this page is exactly the same as https://getbootstrap.com/docs/4.0/examples/blog/. It even goes a step further and indicates that this is the proper URL for your page.
Most automated systems will stop parsing your page after seeing a <link rel="canonical"> tag and instead parse the linked page as though it was the current one. This is where Facebook et al. are getting the Bootstrap metadata from.
TL;DR: Remove this line.
For future reference, you can use Facebook’s Sharing Debugger to troubleshoot problems like this. For the given URL, this is the current result:
Note the Canonical URL and Redirect Path fields, which indicate my above diagnosis.

You need to use something like react-helmet or react-meta-tags to set your <head> data correctly. The data you are looking to set would be openGraph data which can be found here.

Not sure if this is the answer you were looking for but I was searching for how to update the info your react app shows when you preview the link in some other app. Every solution I tried wasn't working with github pages and react (react-helmet, react-meta-tags, react-document-meta). What ended up working was that you can edit the index.html located inside the public folder to change this info. Include this somewhere in the head:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/IMDB.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<title>IMDB</title>
<meta property="og:audio" content="http://example.com/bond/theme.mp3" />
<meta property="og:description"
content="Sean Connery found fame and fortune as the
suave, sophisticated British agent, James Bond." />
<meta property="og:determiner" content="the" />
<meta property="og:locale" content="en_GB" />
<meta property="og:locale:alternate" content="fr_FR" />
<meta property="og:locale:alternate" content="es_ES" />
<meta property="og:site_name" content="IMDb" />
<meta property="og:video" content="http://example.com/bond/trailer.swf" />
Example from https://ogp.me/

You can also use the ogtag.me API that allows you to shorten your links dynamically and send the data you want it to display on social platforms and then use this shorten links in your share buttons.

Related

og:url ignored in SPA when redirected to a route handling the rendering of required meta tags

I'm trying to implement social share buttons in my SPA that's served over Azure CDN.
In order overcome the problem of bots not executing javascript on my page I'm redirecting these (via 302) to my express.js backend where I'm rendering and returning valid HTML with all the required og: META tags populated, all works just fine.
<head>
<meta property="og:title" content="${story?.headline}" />
<meta property="og:description" content="${introText}" />
<meta property="og:image" content="https://backend-example.com/${imageUrl}" />
<meta property="og:url" content="https://www.example.com/story/${story?.id}" />
</head>
The problem is, the og:url tag is ignored in the thumbnail rendered by social networds, and istead of:
"https://www.example.com/story/11"
it shows the URL of my backend:
"https://www.backend-example.com/story/11"
I'm wondering if there's a possible workaround for this so the thumbnail will show the SPA's URL instead of the backends?
Best,
vedtam

How can i create Featured Image function in core php not in wordpress

There is a function for every page in wordpress so if we share link in other websites then it fetches title, description and featured image of that page / post, but i wanna make this functionality in core php not in wordpress, how can i make it so when i share link to other website then it fetches only that one featured image ? without featured image functionality it fetches only logo.
please could you help me?
If I understand correctly, all you need to do is add OpenGraph on your PHP/HTML header.
<meta property="og:title" content="Your desired title" />
<meta property="og:description" content="Some sentences here" />
<meta property="og:url" content="https://www.yourdomain.com/filename.php" />
<meta property="og:site_name" content="rumahweb.com" />
<meta property="og:image" content="https://www.yourdomain.com/featured-image.png" />
Insert above code (and adjust the value as necessary) inside your HEAD section of your HTML/PHP file.

HTML5 - html, prefix and meta related

I am new to HTML5. I did some researches on prefix and OGP, but I still cannot figure out the following
<head prefix="og: http://ogp.me/ns#">
<title>something</title>
<meta property="og:title" content="something"/>
<meta prefix="og: http://ogp.me/ns#" property="og:image"
content="http://something.com/img/social-image.png" />
</head>
<head prefix="og: http://ogp.me/ns#">What's "og: http://ogp.me/ns#"? What does it do?
I found this from quora (https://www.quora.com/What-does-this-tag-mean-html-lang-en-US-prefix-og-http-ogp-me-ns), but I cannot understand it.
The Open Graph protocol enables any web page to become a rich object
in a social graph. For instance, this is used on Facebook to allow any
web page to have the same functionality as any other object on
Facebook.
What does "become a rich object" mean?
2.Why do we need these two lines, <title>something</title> and <meta property="og:title" content="something"/>? Aren't they same?
3.Why do we need to set the meta prefix again in the third line? Didn't we do it in the head?
<meta prefix="og: http://ogp.me/ns#" property="og:image"
content="http://something.com/img/social-image.png" />
Thanks a lot!
What you're describing is called Open Graph Protocol, and it essentially means you're using that template above to turn a webpage into a graph object. You need four parts: og:title, og:type, og:url, and og:image, which are described in detail here. This is the basic metadata you need to use Open Graph Protocol - if you don't have it, Open Graph won't work.

Twitter card not working even after validation

I want to add a Twitter button on my website to share content, as well as a Twitter card. I've already added the meta tags.
Here is the code for my share button:
Tweet
This is the code for the meta tags I've added as well:
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="#nytimes">
<meta name="twitter:creator" content="#SarahMaslinNir">
<meta name="twitter:title" content="When Great Minds Don’t Think Alike">
<meta name="twitter:description" content="How much does culture influence creative thinking?">
<meta name="twitter:image" content="http://176.32.230.11/trialandtest.com/assets/images/profile-img.jpg">
Here is the link to my site:
http://176.32.230.11/trialandtest.com/
I'd be grateful if someone could assist me as to where I am going wrong, because I have my URL whitelisted on Twitter, but when I try to share something it does not share the content on the preview window and shares the old one.
Your share url should be dynamic. I think when you click on the share button it is taking your static url ie. http://176.32.230.11/trialandtest.com

Changing Umbraco 7 Website Name

Following the Umbraco Tutorial , I have installed an empty website, then used the Modernizr template as advised.
I got the same result as tutorial, then I wanted to go ahead and make some other changes such as modifying the website name, since the template shows the current page name instead of The Website name.
(please look at the h1.title item in the below image)
What I have done:
In the HomePage under the Document Type node, I have added a new tab that I named: "Site Config Data", then added to it a new property: "websiteName", then in the Master page template header I inserted the same property field with the recursive option checked, so now it looks like the next:
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>#Umbraco.Field("websiteName", recursive: true)</title>
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="/css/style.css">
<script src="/scripts/libs/modernizr-2.0.6.min.js"></script>
</head>
Then in the Home page under the Content node, I entered the required website name in the newly added Textbox, then saved and published successfully.
But when I browse to the home page and click on the menu bar options, still the current page shows instead of the website name.
I googled on this issue, but could find nothing, any ideas please ?
A stupid error, the property in the Master template was in the wrong place, it should be in the body tag not in the head tag as shown above in the code block.
Now as I changed it, the website name shows normally in the right place.

Categories

Resources