Expand my Community achievements bar.

SOLVED

Share AEM URL in social media

Avatar

Level 3

I want to  share the URL of aem site page on social media, such as Facebook, LinkedIn, Twitter, etc. It should be display as  thumbnail image, title and description?. Is it possible.

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

From the looks of it, you shouldn't use the out of the box social share component, as it is depreciated in the latest versions of the WCM Core Components, v3.

So a quick answer, and Nope, it's not out of the box behavior that AEM ships for free. You need to create your own custom implementation.


Create your own implementation of the social feature. Id suggest you to put the implementation code in your own base page component, and then add some author editable fields in the page properties, so you can enable and disable features. Next your sightly would need to expose special meta-data tags which will be used by the social media platform itself. 

Just for testing, paste this meta tags (mentioned in the code editor) into the <head> HTML element, view the page as published, then source edit and this is what you are going to have to create as the page is rendered for customers; its probably best for you to hard code these values at first during your development phase, so you know exactly which tags you would need. if you'd like to see a live example, visit this website, https://sourcedcode.com/blog/aem/advancing-your-aem-skills-tips-for-junior-developers. View the page source, and expect all the required meta fields to exist. Once you understand what you are looking at, try to share it on Linkedin, Facebook, and you'll see the magic.

 

 

<!-- Facebook Open Graph Tags -->
<meta property="og:title" content="Your Page Title">
<meta property="og:description" content="Your Page Description">
<meta property="og:image" content="https://sourcedcode.com/storage/2019/09/cropped-aem_logo.jpeg">
<meta property="og:url" content="URL of the Page">
<meta property="og:type" content="website">

<!-- Twitter Card Tags -->
<meta name="twitter:title" content="Your Page Title">
<meta name="twitter:description" content="Your Page Description">
<meta name="twitter:image" content="https://sourcedcode.com/storage/2019/09/cropped-aem_logo.jpeg">
<meta name="twitter:card" content="summary_large_image">

<!-- LinkedIn Open Graph Tags -->
<meta property="og:title" content="Your Page Title">
<meta property="og:description" content="Your Page Description">
<meta property="og:image" content="https://sourcedcode.com/storage/2019/09/cropped-aem_logo.jpeg">
<meta property="og:url" content="URL of the Page">
<meta property="og:type" content="website">
<meta property="og:site_name" content="Your Site Name">
<meta property="og:locale" content="en_US">
<meta property="article:author" content="Author Name">
<meta property="article:published_time" content="Publish Date">
<meta property="article:modified_time" content="Modified Date">
<meta property="article:section" content="Section">
<meta property="article:tag" content="Tag">

<!-- LinkedIn Company-specific Tags (for company pages) -->
<meta property="og:company" content="Your Company Name">
<meta property="og:company_id" content="Your LinkedIn Company ID">

<!-- Pinterest Rich Pins (for articles) -->
<meta name="pinterest:rich:pin:title" content="Your Page Title">
<meta name="pinterest:rich:pin:description" content="Your Page Description">
<meta name="pinterest:rich:pin:image_url" content="https://sourcedcode.com/storage/2019/09/cropped-aem_logo.jpeg">
<meta name="pinterest:rich:pin:link" content="URL of the Page">

<!-- Pinterest App-Install Pins -->
<meta name="pinterest:app_name:iphone" content="App Name for iPhone">
<meta name="pinterest:app_name:ipad" content="App Name for iPad">
<meta name="pinterest:app_name:googleplay" content="App Name for Android">
<meta name="pinterest:app_url:iphone" content="URL to App on the App Store">
<meta name="pinterest:app_url:ipad" content="URL to App on the App Store">
<meta name="pinterest:app_url:googleplay" content="URL to App on Google Play">

<!-- Facebook and Twitter require at least the following three tags: title, description, and image -->
<!-- LinkedIn requires at least the following two tags: title and image_url -->
<!-- Pinterest requires at least the following two tags: title and image_url -->

 

 

 

For Facebook Open Graph Tags:

For Twitter Card Tags:

For LinkedIn Open Graph Tags:

For Pinterest Rich Pins:

You can visit these links to understand more about the individual meta tags and how they work for each social media platform. Replace the "URL to Thumbnail Image," "Your Page Title," and other placeholder values with the appropriate content specific to your website and content.


========

Next, what you'd want to do next is determine which values will be rendered in each of the meta tags, like
<meta property="og:title" content="${currentPage.title}">
<meta property="og:description" content="${currentPage.description}">
<meta property="og:image" content="${page.imageUrl}">

 

 

========

 

 

PRO TIP: instead of overloading your sightly.html file, you should create backend logic to pull together and generate a hashMap of all the meta fields you need, and then using sightly, to traverse through the map, and render each block on HTML element on the page.

private void initMetadata() {
metadata = new LinkedHashMap<>();
if (socialMediaEnabled) {
WebsiteMetadata websiteMetadata = createMetadataProvider();
put(OG_TITLE, websiteMetadata.getTitle());
put(OG_URL, websiteMetadata.getURL());
put(OG_TYPE, websiteMetadata.getTypeName());
put(OG_SITE_NAME, websiteMetadata.getSiteName());
put(OG_IMAGE, websiteMetadata.getImage());
put(OG_DESCRIPTION, websiteMetadata.getDescription());

if (pinterestEnabled && websiteMetadata instanceof ProductMetadata) {
ProductMetadata productMetadata = (ProductMetadata) websiteMetadata;
put(OG_PRODUCT_PRICE_AMOUNT, productMetadata.getProductPriceAmount());
put(OG_PRODUCT_PRICE_CURRENCY, productMetadata.getProductPriceCurrency());
}
}
}

 

View solution in original post

3 Replies

Avatar

Level 6

Yes it is possible. If you want to achieve this you need make sure that og:image and og:description is available on DOM.

By default if you generate thumbnail of a page and publish it, the thumbnail image is added on og:image on DOM. 

Go to the page properties of the page you want to share. then go to thumbnail

kaikubad_0-1690306105644.png

Then you will see three options. Generate preview, upload and select image. Chose whatever is convenient for you

kaikubad_1-1690306188260.png

On head section of dom you will find something like this

kaikubad_2-1690306523857.png

In case you need to override default behavior you can check this link
https://github.com/adobe/aem-core-wcm-components/blob/main/bundles/core/src/main/java/com/adobe/cq/w...

 

 

Avatar

Employee

@Dillibabu77 ,

Yes ,it is possible,to ensure that the shared URL displays a thumbnail image, title, and description.You can implement the appropriate metadata tags on your AEM site pages.

Here's how you can achieve this:

Open Graph Tags (Facebook and LinkedIn):

->Open Graph (OG) tags are metadata tags that define how content should appear when shared on social media platforms like Facebook and LinkedIn.
In your AEM site's page template or component's HTML, include the necessary Open Graph tags within the <head> section. For example:

<meta property="og:title" content="Your Page Title">
<meta property="og:description" content="Your Page Description">
<meta property="og:image" content="URL to Thumbnail Image">
<meta property="og:url" content="URL of the Page">
<meta property="og:type" content="website">

 

->Replace the placeholder values (e.g., "Your Page Title," "Your Page Description," "URL to Thumbnail Image," etc.) with the actual title, description, image URL, and page URL of your AEM site page.

 

-->For Twitter Card Tags (Twitter):


->Include the necessary Twitter Card tags within the <head> section of your AEM site's page template or component's HTML. For example:

<meta name="twitter:title" content="Your Page Title">
<meta name="twitter:description" content="Your Page Description">
<meta name="twitter:image" content="URL to Thumbnail Image">
<meta name="twitter:card" content="summary_large_image">

 

Replace the placeholder values with the actual title, description, and image URL of your AEM site page.

 

By including these metadata tags in your AEM site's page templates or components, the social media platforms will use this information when users share the page URL, resulting in a preview with the thumbnail image, title, and description.

Avatar

Correct answer by
Community Advisor

From the looks of it, you shouldn't use the out of the box social share component, as it is depreciated in the latest versions of the WCM Core Components, v3.

So a quick answer, and Nope, it's not out of the box behavior that AEM ships for free. You need to create your own custom implementation.


Create your own implementation of the social feature. Id suggest you to put the implementation code in your own base page component, and then add some author editable fields in the page properties, so you can enable and disable features. Next your sightly would need to expose special meta-data tags which will be used by the social media platform itself. 

Just for testing, paste this meta tags (mentioned in the code editor) into the <head> HTML element, view the page as published, then source edit and this is what you are going to have to create as the page is rendered for customers; its probably best for you to hard code these values at first during your development phase, so you know exactly which tags you would need. if you'd like to see a live example, visit this website, https://sourcedcode.com/blog/aem/advancing-your-aem-skills-tips-for-junior-developers. View the page source, and expect all the required meta fields to exist. Once you understand what you are looking at, try to share it on Linkedin, Facebook, and you'll see the magic.

 

 

<!-- Facebook Open Graph Tags -->
<meta property="og:title" content="Your Page Title">
<meta property="og:description" content="Your Page Description">
<meta property="og:image" content="https://sourcedcode.com/storage/2019/09/cropped-aem_logo.jpeg">
<meta property="og:url" content="URL of the Page">
<meta property="og:type" content="website">

<!-- Twitter Card Tags -->
<meta name="twitter:title" content="Your Page Title">
<meta name="twitter:description" content="Your Page Description">
<meta name="twitter:image" content="https://sourcedcode.com/storage/2019/09/cropped-aem_logo.jpeg">
<meta name="twitter:card" content="summary_large_image">

<!-- LinkedIn Open Graph Tags -->
<meta property="og:title" content="Your Page Title">
<meta property="og:description" content="Your Page Description">
<meta property="og:image" content="https://sourcedcode.com/storage/2019/09/cropped-aem_logo.jpeg">
<meta property="og:url" content="URL of the Page">
<meta property="og:type" content="website">
<meta property="og:site_name" content="Your Site Name">
<meta property="og:locale" content="en_US">
<meta property="article:author" content="Author Name">
<meta property="article:published_time" content="Publish Date">
<meta property="article:modified_time" content="Modified Date">
<meta property="article:section" content="Section">
<meta property="article:tag" content="Tag">

<!-- LinkedIn Company-specific Tags (for company pages) -->
<meta property="og:company" content="Your Company Name">
<meta property="og:company_id" content="Your LinkedIn Company ID">

<!-- Pinterest Rich Pins (for articles) -->
<meta name="pinterest:rich:pin:title" content="Your Page Title">
<meta name="pinterest:rich:pin:description" content="Your Page Description">
<meta name="pinterest:rich:pin:image_url" content="https://sourcedcode.com/storage/2019/09/cropped-aem_logo.jpeg">
<meta name="pinterest:rich:pin:link" content="URL of the Page">

<!-- Pinterest App-Install Pins -->
<meta name="pinterest:app_name:iphone" content="App Name for iPhone">
<meta name="pinterest:app_name:ipad" content="App Name for iPad">
<meta name="pinterest:app_name:googleplay" content="App Name for Android">
<meta name="pinterest:app_url:iphone" content="URL to App on the App Store">
<meta name="pinterest:app_url:ipad" content="URL to App on the App Store">
<meta name="pinterest:app_url:googleplay" content="URL to App on Google Play">

<!-- Facebook and Twitter require at least the following three tags: title, description, and image -->
<!-- LinkedIn requires at least the following two tags: title and image_url -->
<!-- Pinterest requires at least the following two tags: title and image_url -->

 

 

 

For Facebook Open Graph Tags:

For Twitter Card Tags:

For LinkedIn Open Graph Tags:

For Pinterest Rich Pins:

You can visit these links to understand more about the individual meta tags and how they work for each social media platform. Replace the "URL to Thumbnail Image," "Your Page Title," and other placeholder values with the appropriate content specific to your website and content.


========

Next, what you'd want to do next is determine which values will be rendered in each of the meta tags, like
<meta property="og:title" content="${currentPage.title}">
<meta property="og:description" content="${currentPage.description}">
<meta property="og:image" content="${page.imageUrl}">

 

 

========

 

 

PRO TIP: instead of overloading your sightly.html file, you should create backend logic to pull together and generate a hashMap of all the meta fields you need, and then using sightly, to traverse through the map, and render each block on HTML element on the page.

private void initMetadata() {
metadata = new LinkedHashMap<>();
if (socialMediaEnabled) {
WebsiteMetadata websiteMetadata = createMetadataProvider();
put(OG_TITLE, websiteMetadata.getTitle());
put(OG_URL, websiteMetadata.getURL());
put(OG_TYPE, websiteMetadata.getTypeName());
put(OG_SITE_NAME, websiteMetadata.getSiteName());
put(OG_IMAGE, websiteMetadata.getImage());
put(OG_DESCRIPTION, websiteMetadata.getDescription());

if (pinterestEnabled && websiteMetadata instanceof ProductMetadata) {
ProductMetadata productMetadata = (ProductMetadata) websiteMetadata;
put(OG_PRODUCT_PRICE_AMOUNT, productMetadata.getProductPriceAmount());
put(OG_PRODUCT_PRICE_CURRENCY, productMetadata.getProductPriceCurrency());
}
}
}