短代码

发布于 2021-09-24  655 次阅读


主题更新后,修改过的短代码会消失,因此在此做备份

其中包含了:github卡片,内嵌YouTube、Bilibili视频,fancybox灯箱。

将以下代码复制到functions.php中。

//github card
function github($atts,$content=null,$code=""){
    $return = '<iframe frameborder="0" scrolling="0" allowtransparency="true" src="https://api.2heng.xin/github-card/?repo=';
    $return .= $content;
    $return .= '" width="400" height="200" style="margin-left: 50%; transform: translateX(-50%);"></iframe>';
    return $return;
}
add_shortcode('github','github');

//inner video shortcode
function youtube($atts,$content=null,$code=""){
    $return = '<div class="video-container"><iframe height="498" width="100%" src="https://www.youtube.com/embed/';
    $return .= $content;
    $return .= '" frameborder="0" allowfullscreen="allowfullscreen"></iframe></div>';
    return $return;
}
add_shortcode('youtube','youtube');
function bilibili($atts,$content=null,$code=""){
    extract(shortcode_atts(array("danmaku"=>'1'),$atts));
    extract(shortcode_atts(array("page"=>'1'),$atts));
    $return = '<div class="video-container"><iframe src="https://player.bilibili.com/player.html?bvid=';
    $return .= $content;
    $return .= '&page=';
    $return .= $page;
    $return .= '&high_quality=1&danmaku=';
    $return .= $danmaku;
    $return .= '" allowtransparency="true" width="100%" height="498" scrolling="no" frameborder="0" ></iframe></div>';
    return $return;
}
add_shortcode('bilibili','bilibili');

//fancybox
function img($atts,$content=null,$code=""){
    $return = '<a data-fancybox="gallery" href="';
    $return .= $content;
    $return .= '"><img src="';
    $return .= $content;
    $return .= '"></a>';
    return $return;
}
add_shortcode('img','img');