Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How to have a “clean” post content, for excerpt and social networks sharing

How do the websites that are well optimized for sharing and excerpt displays are handling this subject ?

They definitely have separate fields for excerpt / share-text etc. This is the only way to be certain what text gets used.

These sites also make use of special meta tags in the head to send Facebook, Twitter et al. information about the content that is being shared.

The plugin you mention, Yoast SEO, is a quick way to achieve this functionality. You could also build something yourself with custom Meta Fields, depending on your needs.

On a bunch of my sites I use this code to replace the_excerpt with whatever I fill in at Yoast SEO’s meta description field.

/**
 * !Replace the_excerpt with Yoast SEO meta-description
 */
if (function_exists('wpseo_init')){
  add_filter( 'get_the_excerpt', 'wpse_232590_replace_post_excerpt' );
  function wpse_232590_replace_post_excerpt($output)
  {
    $output=get_post_meta(get_the_ID(), '_yoast_wpseo_metadesc', true);
    return $output;
  }
}

So I fill in the Yoast SEO meta description field and that gets used on my site wherever I use the_excerpt. When you don’t want to fill in special content for Twitter and Facebook meta tags you just leave them empty, the meta-description field will be used. So it’s just one extra field that you would have to fill in.

Related Posts:

  1. Replace full content with an excerpt
  2. the_excerpt() in content.php and get_template_part() in single.php
  3. append_content help
  4. How to limit post content and remove image caption from it
  5. Change Content for Specific Page
  6. How to make search and replace in content through php
  7. Hide specific content from excerpts
  8. Displaying latest Posts – fixed height – Excerpt vs. Content?
  9. Excerpt vs content formatting woes
  10. Split the_content into two parts
  11. add share buttons above my posts without plugins
  12. Divide post content in three columns
  13. How do i configure my content to show full posts?
  14. How to show content for posts of a specific category only
  15. The post content just showing up text
  16. Put teaser content, more-link and full content in different divs if existing… Possible?
  17. Display a paragraph in the index page that won’t be displayed in the single post
  18. Scroll over to get definition [closed]
  19. Stop WordPress Wrapping Images In A “P” Tag
  20. Best practices for localizing WordPress content?
  21. if the post has content
  22. How can i display the content in plaintext
  23. I want to have my custom field use HTML, how do I do that?
  24. Get content from one page and show it on another page
  25. remove tags from the_content
  26. Where to hook into post content?
  27. What’s the Best Way to Structure a Multi-Content Blog?
  28. How to Handle Distributed Development Workflow
  29. How can I clear oEmbed caches for YouTube on posts as they are loaded
  30. Modify ‘Read more’ link adding a new class
  31. Get excerpt from $post->post_content
  32. Recommended Books on WordPress for Management and non-Developers?
  33. Total word count for posts by one author
  34. limit the words in the post content and add read more link
  35. Neither the_excerpt() nor the_content() works properly?
  36. Split content into multiple columns using more tag?
  37. Get Content From Blog Page
  38. Show content after the first and second paragraph
  39. Host wp-content on other domain, much like a CDN
  40. WordPress REST API – JSON “Rendered” Content Incorrect
  41. How do I make certain areas editable?
  42. What server settings are required to import WordPress XML file
  43. Custom CSS for full post vs. excerpt (Content Options)
  44. Is there a way to trigger an automatic import of a WP backup on creation of a new WP multisite site?
  45. Site content not showing
  46. How to just show first line of content
  47. Hiding posts and pages in panel
  48. get_the_excerpt() not returning anything when post has no excerpt
  49. Take excerpt of the content of the post and send it as the title to create new post
  50. How to hide and content from auto-generated excerpts?
  51. Convert all youtube link to embed
  52. How to get excerpt correctly formatted
  53. Testing for post title in ‘if/else’ statement returns no content
  54. Add $more_link_text parameter to the_excerpt()
  55. Extremely slow pageload for long post when using the_content?
  56. How Can A Plugin Hook Itself To the End of Every Excerpt?
  57. How to show video from specific category on sidebar?
  58. How to correctly limit the content and strip HTML?
  59. the_excerpt(), get_the_excerpt() and the_content() all killing “the Loop”
  60. Content/Excerpt length control for a specific loop?
  61. wp_insert_post iframe missing
  62. Getting first 20 words without excerpt
  63. Grabbing specific content
  64. What is the proper way to get contents of a page?
  65. Does is_user_logged_in() block search bots?
  66. Combining the_excerpt with the_content
  67. Finding the paragraphs in content
  68. Output string using php printf
  69. Get the Page Content,without generating HTML
  70. content gets scrambled
  71. Conflicting post edit options under dashboard
  72. Disable external (3rd party) CALL (images,fonts..) in Dashboard
  73. Retrieve a specific number of words from post_Content
  74. Get the content inside shortcode and apply external function to it?
  75. Can somebody tell me how I am supposed to be using blogs.dir for network / MU sites?
  76. Why content_arr[‘extended’] removes paragraph tags?
  77. How do I Add HTML to the_excerpt() & the_content() Output?
  78. Is there a way to show only the text editor
  79. How to make author box like this & add after every post?
  80. Hardening wordpress: wp-content file permissions?
  81. Extract an embedded video from the content
  82. same wordpress, 2 domains
  83. Error when adding excerpt to the content through functions.php
  84. How to retrieve text only from a post using WP CLI?
  85. Gutenberg is Adding Additional HTML Tags When Grabbing the Excerpt
  86. Missing content in Pages only
  87. Doctype printed on the page content
  88. Images are searched in the wrong path
  89. Remove Content Filter
  90. Main WordPress site with several flexible clones
  91. Post Format Default Content
  92. Export + Import = wrongly duplicated content
  93. Post titles below the post format content
  94. Show image on the left and content on the right using ul li
  95. What is the precendence of item types within WordPress
  96. Problem on the_excerpt(); function
  97. How To Watermark Audio
  98. Problem with content – not loading
  99. Giving the_excerpt in the place of the_content?
  100. What are the advantages/disadvantages of using jQuery DOM manipulation as opposed to PHP DOM manipulation?
Categories content Tags content, excerpt, social-sharing, the-content
Display div only on the HOMEPAGE
Script Localization doesn’t work

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress