外贸独立站的底层设计密码WordPress 成品站模板
当前位置:首页>WordPress建站>基础教程>WordPress 使用 iframe 嵌入Github Gist代码

WordPress 使用 iframe 嵌入Github Gist代码

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

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
欢迎关注WordPress大学公众号 WPDAXUE
基础教程

为你的 WordPress 站点添加”历史上的今天”功能

2014-4-15 8:58:09

基础教程

将WordPress作者存档链接中的用户名改为用户ID

2014-5-2 12:02:47

3 条回复 A文章作者 M管理员
  1. 国内也有类似Github的服务了

  2. 有空试试看,就是感觉github的速度有点慢。

  3. 撒哈拉的小猫

    面条。。很熟悉的样子

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索