Last active
June 8, 2021 21:25
-
-
Save sybrew/5fac0d3db62136b70d40c8e997dfea09 to your computer and use it in GitHub Desktop.
Replace excerpt TSF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Don't include this tag if PHP has already started. | |
// For: https://wordpress.org/support/topic/auto-generated-meta-description-from-content-not-excerpt/ | |
// I do not recommend using this snippet. | |
add_filter( 'the_seo_framework_fetched_description_excerpt', function( $excerpt, $depr, $args ) { | |
// There's no excerpt found, might as well stop trying to fetch it again. | |
if ( ! strlen( $excerpt ) ) return $excerpt; | |
$post_id = 0; | |
if ( null === $args ) { | |
$tsf = the_seo_framework(); | |
if ( ! $tsf->is_real_front_page() && $tsf->is_singular() ) { | |
$post_id = $tsf->get_the_real_ID(); | |
} | |
} else { | |
$post_id = empty( $args['taxonomy'] ) ? $args['id'] : 0; | |
} | |
if ( $post_id ) { | |
$post = get_post( $post_id ); | |
// TSF already tried getting the stuff below. Return that, instead of reparsing. | |
if ( empty( $post->post_excerpt ) ) return $excerpt; | |
// TSF doesn't support some page builders, for that'll double your response times, and Google can replace descriptions anyway. | |
$_excerpt = $tsf->uses_non_html_page_builder( $post->ID ) ? '' : $post->post_content; | |
if ( $_excerpt ) { | |
$_excerpt = $tsf->strip_newline_urls( $_excerpt ); | |
$_excerpt = $tsf->strip_paragraph_urls( $_excerpt ); | |
// Overwrite: | |
$excerpt = $_excerpt; | |
} | |
} | |
return $excerpt; | |
}, 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment