post_type ) { return $tweet_body; } // Get the post content and strip shortcodes $content = strip_shortcodes( $post->post_content ); // Convert

and
tags to double line breaks, then strip all other HTML $content = wpautop( $content, false ); $content = wp_strip_all_tags( $content, false ); // Convert double line breaks to single newlines (Twitter displays these as line breaks) $content = preg_replace( "/\n\s*\n/ms", "\n\n", $content ); // Clean up any remaining whitespace $content = trim( $content ); // Truncate if needed, trying to preserve paragraphs $max_length = 275; // Max tweet length with room for ellipsis if ( strlen( $content ) > $max_length ) { $content = force_balance_tags( htmlspecialchars_decode( $content ) ); $content = mb_substr( $content, 0, $max_length ); $content = preg_replace( '/\s+\S*$/', '…', $content ); } return $content; } add_filter( 'autoshare_for_twitter_body', 'custom_tweet_body', 10, 2 ); /** * Removes the URL from the tweet. * * @param string $url The original URL. * @param object $post The post object. * @return string An empty string to remove the URL. */ function remove_tweet_url( $url, $post ) { // Only remove URL for 'note' post type if ( 'note' !== $post->post_type ) { return $url; } return ''; } add_filter( 'autoshare_for_twitter_post_url', 'remove_tweet_url', 10, 2 );