wordpress ブログカードが表示されない時の対処法

参考URL

https://hyperts.net/wordpress-oembed-problem/

足りないソースコードをheader内に追加する方法
fanctions.phpにコピペでOK!

function my_add_embed() {
	$insert = '';
	$insert .= '<link rel="https://api.w.org/" href="' . site_url() . '/wp-json/" />' . "\n";
	$insert .= '<link rel="alternate" type="application/json+oembed" href="' . site_url() . '/wp-includes/oembed/1.0/embed?url=' . urlencode( ( empty( $_SERVER[ 'HTTPS' ] ) ? 'http://' : 'https://' ) . $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ] ) . '" />' . "\n";
	$insert .= '<link rel="alternate" type="text/xml+oembed" href="' . site_url() . '/wp-includes/oembed/1.0/embed?url=' . urlencode( ( empty( $_SERVER[ 'HTTPS' ] ) ? 'http://' : 'https://' ) . $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ] ) . '&#038;format=xml" />' . "\n";
	$insert .= '<script type="text/javascript" src="' . site_url() . '/wp-includes/js/wp-embed.min.js"</script>' . "\n";
	echo $insert;
}
add_action( 'wp_head', 'my_add_embed' );

「http://自分のドメイン」は、ワードプレス本体を設置しているディレクトリのことなので、「site_url()」を使います。

「独自のパラメータ」は、application/json+oembedの方は「ページURL」のエンコード
「text/xml+oembed」の方は「ページURL&format=xml」のエンコードなので、URLをエンコードしてくれる「urlencode()」と、ページのURLを取得してくれる「( empty( $_SERVER[ ‘HTTPS’ ] ) ? ‘http://’ : ‘https://’ ) . $_SERVER[ ‘HTTP_HOST’ ] . $_SERVER[ ‘REQUEST_URI’ ] 」を使います。