Created
December 7, 2019 07:05
-
-
Save mono96/a3e0b3291d6f902a4489efacc52853fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ブログカードカスタマイズ | |
// 取得成功時 | |
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