Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct the Twitter Card in social share preview #1498

Merged
merged 3 commits into from
Jan 27, 2024

Conversation

bigsk1
Copy link
Contributor

@bigsk1 bigsk1 commented Jan 20, 2024

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Description

Twitter cards were not displaying correctly due to relative URL paths. The proposed changes ensure that Twitter card meta tags use absolute URLs, aligning with best practices for SEO and social media compatibility

Additional context

This pull request addresses the issue reported in #1497 where

Key changes include:

  • Updating head.html to dynamically generate absolute URLs for Twitter card images.
  • Ensuring compatibility with various social media platforms through testing.

This update has been tested across multiple social platforms to ensure correct display of Twitter card images

Special thanks to @timothystewart6 for his significant contributions to testing and refining the code.

@bigsk1
Copy link
Contributor Author

bigsk1 commented Jan 20, 2024

I've attached a screenshot from the browser's HTML view to demonstrate the successful implementation and correct functioning of the Open Graph and Twitter card metadata updates. This image visually confirms that:

  • The Open Graph (og:image) and Twitter card (twitter:image) meta tags are now correctly utilizing absolute URLs.
  • Each social media meta tag appears only once, thereby resolving any previous issues of duplication.
  • The metadata is properly formatted and aligned with SEO best practices and social media platform requirements.

This visual evidence supports the changes made in this pull request, offering a clear depiction of the improved metadata handling in the site's HTML structure.

open_graph_and_twitter_cards

@bigsk1 bigsk1 force-pushed the fix-twitter-cards branch 2 times, most recently from 82f3ff8 to e635589 Compare January 24, 2024 10:58
@bigsk1 bigsk1 changed the title fix-twitter-cards in head.html fix(head.html): correct Twitter cards integration Jan 24, 2024
Copy link
Owner

@cotes2020 cotes2020 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting the patch, but there are a couple of problems with the modifications: firstly, you weren't clear about the purpose of img-url.html and strangely duplicated a piece of code, and lastly, there's another bug in the site.social_preview_image section that you didn't catch: there's no Twitter Card image defined (a meta element for twitter:image).

Comment on lines 21 to 23
{% assign old_meta_clip = '<meta name="twitter:card"' %}
{% assign new_meta_clip = og_image | append: old_meta_clip %}
{% assign seo_tags = seo_tags | replace: old_meta_clip, new_meta_clip %}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of copying this code from below to here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on your suggestions, I have revised the implementation to better integrate with the existing structure of the head.html

In this update, I've focused on refining the handling of Twitter card URLs. Specifically, I have ensured that the absolute URLs are generated correctly for Twitter cards, while maintaining the img-url.html include. This change aims to address the issue with Twitter cards not displaying images correctly, which was the core problem in my initial pull request.

I've pushed these changes in the latest commit and would appreciate your review and feedback

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With these changes I have verified the correct html output

open_graph_and_twitter_cards

and have verified open graph and twitter cards are displayed correctly on socials

https://www.opengraph.xyz/url/https%3A%2F%2Fbigsk1.com%2Fposts%2FFile-Converter%2F

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you didn't understand what I was commenting on, never mind, I'll finish the patch.

@cotes2020 cotes2020 mentioned this pull request Jan 27, 2024
1 task
@cotes2020 cotes2020 force-pushed the fix-twitter-cards branch 2 times, most recently from 4612509 to caff3b7 Compare January 27, 2024 21:42
Copy link
Owner

@cotes2020 cotes2020 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bigsk1 my patch fixes the issue mentioned in #1497, and the missing twitter:image for site.social_preview_image is also fixed.

bigsk1 and others added 3 commits January 28, 2024 05:49
The Twitter card metadata in head.html was updated to ensure proper rendering of cards in tweets. This includes adjustments to the meta tags for title, description, and image attributes.
@cotes2020 cotes2020 changed the title fix(head.html): correct Twitter cards integration fix: correct the Twitter Card in social share preview Jan 27, 2024
@cotes2020 cotes2020 merged commit 74f1662 into cotes2020:master Jan 27, 2024
5 checks passed
@bigsk1
Copy link
Contributor Author

bigsk1 commented Jan 27, 2024

I am getting no visible image with the refactor real patch

absolute urls are not being shown for twitter:image and og:image

<meta property="twitter:image" content="/assets/images/bigsk1.webp">

realpatch_img_twitter

peteryuhang added a commit to peteryuhang/peteryuhang.github.io that referenced this pull request Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Twitter Cards Missing Images
2 participants