首页>文档>源码技巧>Wordpress>B2美化>7B2主题页眉下方添加顶部通栏广告

此组别内的文章

需要支持?

如果通过文档没办法解决您的问题,请提交工单获取我们的支持!

7B2主题页眉下方添加顶部通栏广告

7B2主题页眉下方添加顶部通栏广告。B2主题默认没有设置页眉下方的顶部通栏广告位,但是预留了一个钩子 b2_content_before,我们可以通过该钩子插入广告代码。

7B2主题页眉下方添加顶部通栏广告插图
7B2页眉下方添加顶部通栏广告

B2主题提供了子主题,建议采用子主题方式来添加自定义代码

代码示例如下,请根据自己的需要修改,将代码添加到当前激活主题的 functions.php:

/**
 * 添加图片广告到B2主题页眉下方
 * https://www.dzcrv.com
 */
add_action('b2_content_before', function(){
    echo '<div class="dddd ads-after-header">
            <div class="wrapper">
                    <a target="_blank" href="https://www.dzcrv.com">
                            <img width="598" height="80" alt="点击查看广告位详情" src="https://www.dzcrv.com/img/2022/07/joowp.png" >
                    </a>
                    <a target="_blank" href="https://www.dzcrv.com">
                            <img width="598" height="80" alt="外贸建站,就用成品站模板" src="https://www.dzcrv.com/img/2022/08/mubanjz.png" >
                    </a>
            </div>
    </div>';
});

样式代码参考如下,根据自己的需要调整,可以添加到主题的 style.css:

.vips .ads-after-header {
    display: none;
}
.ads-after-header {
    margin-bottom: 16px;
}
.ads-after-header a {
    display: inline-block;
    width: 49.8%;
    max-width: 598px;
}
.ads-after-header a:first-child {
    margin-right: 0.4%;
}
.ads-after-content {
    margin-top: 16px;
}
.post-style-5 .ads-after-header {
    display: none;
}
@media screen and (max-width: 768px){
    .ads-after-header {
        margin-bottom: 4px;
    }
    .ads-after-header a {
        width: 100%;
        max-width: 768px;
        margin-bottom: 2px;
    }
    .ads-after-header a:first-child {
        margin-right: 0;
    }
}
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索