'_yoast_wpseo_title', 'description' => '_yoast_wpseo_metadesc', 'keyword' => '_yoast_wpseo_focuskw' ); case 'rankmath': return array( 'title' => 'rank_math_title', 'description' => 'rank_math_description', 'keyword' => 'rank_math_focus_keyword' ); } return null; } /** @return array{metaTitle: ?string, metaDescription: ?string, keyword: ?string} */ function suiko_seo_read( $post_id ) { $keys = suiko_seo_keys(); if ( ! $keys ) { $post = get_post( $post_id ); return array( 'metaTitle' => null, 'metaDescription' => $post && $post->post_excerpt ? $post->post_excerpt : null, 'keyword' => null ); } $v = function ( $k ) use ( $post_id ) { $x = get_post_meta( $post_id, $k, true ); return is_string( $x ) && '' !== $x ? $x : null; }; return array( 'metaTitle' => $v( $keys['title'] ), 'metaDescription' => $v( $keys['description'] ), 'keyword' => $v( $keys['keyword'] ) ); } /** Writes the fields given (null leaves a field untouched). Without an SEO plugin, the description goes to the excerpt. */ function suiko_seo_write( $post_id, $seo ) { if ( ! is_array( $seo ) ) { return; } $keys = suiko_seo_keys(); if ( ! $keys ) { if ( isset( $seo['metaDescription'] ) && is_string( $seo['metaDescription'] ) ) { wp_update_post( array( 'ID' => $post_id, 'post_excerpt' => wp_strip_all_tags( $seo['metaDescription'] ) ) ); } return; } foreach ( array( 'metaTitle' => 'title', 'metaDescription' => 'description', 'keyword' => 'keyword' ) as $field => $k ) { if ( isset( $seo[ $field ] ) && is_string( $seo[ $field ] ) ) { update_post_meta( $post_id, $keys[ $k ], wp_strip_all_tags( $seo[ $field ] ) ); } } }