Skip to content

Instantly share code, notes, and snippets.

@mono96
Created December 7, 2019 07:05
Show Gist options
  • Save mono96/a3e0b3291d6f902a4489efacc52853fe to your computer and use it in GitHub Desktop.
Save mono96/a3e0b3291d6f902a4489efacc52853fe to your computer and use it in GitHub Desktop.
// ブログカードカスタマイズ
// 取得成功時
add_filter(
'wp_oembed_blog_card_blog_card_template',
function( $html, $cache ) {
$url = '';
preg_match( '/<a href=\"(.*?)\".*?>/mis', $html, $matches );
if ( is_array( $matches ) && 1 <= count( $matches ) ) {
$url = $matches[1];
}
if ( 0 === strpos( $url, home_url() ) ) {
$target = '_self';
} else {
$target = '_blank';
}
$cached_time = isset( $cache['cached_time'] ) ? date_i18n( 'd/m/y H:i:s', $cache['cached_time'] ) : null;
ob_start();
?>
<div class="wp-oembed-blog-card" data-cached-time="<?php echo esc_attr( $cached_time ); ?>">
<a href="<?php echo esc_url( $url ); ?>" target="<?php echo esc_attr( $target ); ?>">
<div class="wp-oembed-blog-card__body">
<div class="wp-oembed-blog-card__title">
<?php echo esc_html( $cache['title'] ); ?>
</div>
</div>
</a>
</div>
<?php
return ob_get_clean();
},
100,
2
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment