在网上看到在Gists地址后边加上pibb就可以生成调用的Html,刚好In笔记需要调用一些Gist的代码,就写了下边的代码。
在主题functions.php加入代码:
/**
* WordPress 使用 iframe 嵌入Github Gist代码
* https://www.wpdaxue.com/wp-iframe-handler-gist.html
*/
function wp_iframe_handler_gist( $matches, $attr, $url, $rawattr ) {
$iframe = '<iframe width="100%" height="300" src="https://gist.github.com/'. esc_attr($matches[1]) .'/'. esc_attr($matches[2]) . '.pibb" frameborder=0 ></iframe>';
return apply_filters( 'iframe_gist', $iframe, $matches, $attr, $url, $rawattr );
}
wp_embed_register_handler( 'gist_iframe', '#https://gist.github.com/(.*?)/([\d]+)#i', 'wp_iframe_handler_gist' ); |
/**
* WordPress 使用 iframe 嵌入Github Gist代码
* https://www.wpdaxue.com/wp-iframe-handler-gist.html
*/
function wp_iframe_handler_gist( $matches, $attr, $url, $rawattr ) {
$iframe = '<iframe width="100%" height="300" src="https://gist.github.com/'. esc_attr($matches[1]) .'/'. esc_attr($matches[2]) . '.pibb" frameborder=0 ></iframe>';
return apply_filters( 'iframe_gist', $iframe, $matches, $attr, $url, $rawattr );
}
wp_embed_register_handler( 'gist_iframe', '#https://gist.github.com/(.*?)/([\d]+)#i', 'wp_iframe_handler_gist' );
使用的时候,只需要单独起一行,然后直接插入对应的地址即可,比如:
https://gist.github.com/ccbikai/11216526
来源:
https://www.wpdaxue.com/wp-iframe-handler-gist.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32689.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57