一个分享WordPress、Zblog、Emlog、Typecho等主流博客的教程网站!
当前位置:网站首页 > WordPress教程 > 正文

WordPress 使用 iframe 嵌入Github Gist代码

作者:xlnxin发布时间:2021-04-15分类:WordPress教程浏览:382


导读:在网上看到在Gists地址后边加上pibb就可以生成...

在网上看到在Gists地址后边加上pibb就可以生成调用的Html,刚好In笔记需要调用一些Gist的代码,就写了下边的代码。

在主题functions.php加入代码:

123456789
/** * 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

标签:wordpresshtml主题