こんな感じではどうでしょうか?
functions.php に、
function add_description_meta() {
global $post;
if ( isset( $post ) ) {
if ( is_single() ) {
$description = get_post_meta( $post->ID, 'カスタムフィールド名', true );
$description = mb_strimwidth( preg_replace( '/[\n\r]/', '', strip_tags( $description ) ), 0, 120, '...', 'UTF-8' );
echo '<meta name="description" content="' . esc_attr( $description ) . '" />' . "\n";
}
}
}
add_action( 'wp_head', 'add_description_meta', 1 );
All in One SEO Pack プラグインを使用している場合は、aioseop_description フィルターフックを使用するのもいいかもしれません。
例:
function my_aioseop_description( $description ){
global $post;
if ( isset( $post ) ) {
if ( is_single() ) {
$description = get_post_meta( $post->ID, 'カスタムフィールド名', true );
$description = mb_strimwidth( preg_replace( '/[\n\r]/', '', strip_tags( $description ) ), 0, 120, '...', 'UTF-8' );
}
}
return $description;
}
add_filter( 'aioseop_description', 'my_aioseop_description' );