在特定博客帖子上添加功能 - wordpress multsite

时间:2015-09-23 15:14:39

标签: wordpress function post

民间,

我有一个wordpress多站点。 我需要添加一个功能,只在特定的博客中,它会在每个帖子的末尾添加一个iframe。 我怎么能这样做?

2 个答案:

答案 0 :(得分:0)

你只需要向the_content函数添加一个非常简单的钩子。您面临的问题是,您只需要影响其中一个博客而不是所有博客。

幸运的是,WordPress允许您使用get_current_blog_id()获取博客ID。使用此功能,您可以识别哪个博客是哪个博客,只有在使用相应的博客时才添加自定义代码。

将其添加到当前主题的functions.php文件中。您需要弄清楚博客ID是什么并修改iframe代码,但这应该可以帮到您:

function custom_content_hook($content) {
    if( get_current_blog_id() == INSERT_BLOG_ID ){
        $content .= '<iframe src="" frameborder="0" scrolling="no" width="" height=""></iframe>';
    }
    return $content;
}

add_filter( 'the_content', 'custom_content_hook' );

您仍然可以像往常一样在模板文件中使用the_content()

答案 1 :(得分:0)

最终代码如下所示:

function custom_content_hook($content){

    $iframe = '<iframe src="#" frameborder="0" height="280px" width="620px"></iframe>';

    if( is_single() ){
        $content .= $iframe;
    }

    return $content;
}

add_filter( 'the_content', 'custom_content_hook' );