Skip to content

Instantly share code, notes, and snippets.

@waviaei
Last active June 4, 2021 15:36
Show Gist options
  • Select an option

  • Save waviaei/25e4b324e19f986151b2a8f7e571fe1c to your computer and use it in GitHub Desktop.

Select an option

Save waviaei/25e4b324e19f986151b2a8f7e571fe1c to your computer and use it in GitHub Desktop.
add_filter( 'wpseo_metadesc', function ($trim) {
if ( is_singular() ) {
if ( empty( $trim ) ) {
// If excerpt is empty, use core's auto-generate excerpt to put excerpt string back in to the var.
// 返ってきた抜粋が空白の場合、コアの自動抜粋・抜粋取得処理を使って抜粋を入れ直す.
$trim = get_the_excerpt();
// If you prefer to, additionally, trimm at "。" (full stop, if any), then you can do this instead of above.
// コアが作る自動抜粋の中に句点がもしあれば、句点の後は切り捨てたい場合.
// $excerpt = get_the_excerpt();
// $punctuation = mb_strrpos( $excerpt, '。' );
// $punctuation = ( false !== $punctuation ) ? $punctuation + 1 : null;
// $trim = mb_substr( $excerpt, 0, $punctuation );
}
}
return $trim;
}, 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment