CN2.HK 是专业经营国际CN2网络的服务商,为大陆中小企业提供稳定、安全、合规的国际互联网接入服务。

香港云 cn2.hk 香港云 cn2.hk

服务热线:400 888 9543

服务信箱:idc@cn2.hk

WordPress 主题 CoreNext

在网上看到在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' );

使用的时候,只需要单独起一行,然后直接插入对应的地址即可,比如:

https://gist.github.com/ccbikai/11216526


发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

在线客服