Open snarfed opened 7 years ago
the patch below fixes this for me. it's currently up and running on https://snarfed.org/ . i'm putting together a PR, but i wanted to give you all a heads up and check that this sounds ok first. thanks in advance!
@@ -100,10 +104,11 @@ function jetpack_og_tags() {
$tags['og:url'] = get_permalink( $data->ID );
if ( ! post_password_required() ) {
- if ( ! empty( $data->post_excerpt ) ) {
- $tags['og:description'] = preg_replace( '@https?://[\S]+@', '', strip_shortcodes( wp_kses( $data->post_excerpt, array() ) ) );
+ $excerpt = get_the_excerpt( $data );
+ if ( ! empty( $excerpt ) ) {
+ $tags['og:description'] = preg_replace( '@https?://[\S]+@', '', strip_shortcodes( wp_kses( $excerpt, array() ) ) );
} else {
- $exploded_content_on_more_tag = explode( '<!--more-->', $data->post_content );
+ $exploded_content_on_more_tag = explode( '<!--more-->', apply_filters( 'the_content', $data->post_content ) );
$tags['og:description'] = wp_trim_words( preg_replace( '@https?://[\S]+@', '', strip_shortcodes( wp_kses( $exploded_content_on_more_tag[0], array() ) ) ) );
}
}
Related: #2899
fwiw, i briefly looked at a couple other markdown plugins just now that work the same way, ie store raw markdown in post_content
and render it dynamically, and they both suffer from the same problem:
This issue has been marked as stale. This happened because:
No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.
hi! right now, when og:description comes from the post excerpt or content, it pulls them directly from the db, bypassing plugins that otherwise modify them via filter and hooks. this can be a problem for sites that depend on those modifications.
Steps to reproduce the issue
as an example, i author and store post content in markdown, and use a plugin to render that to HTML. jetpack currently puts the raw markdown content directly into
og:description
. e.g. with this post content:What I expected
I expected the post content to be rendered, then HTML tags stripped, resulting in:
What happened instead
instead, the raw markdown link syntax surfaced in
og:description
:...and ultimately also in the facebook preview and twitter card. :/