首页 > 解决方案 > 在functions.php的标题下方添加横幅

问题描述

我正在尝试在所选页面的标题下方添加横幅/内容。我尝试了下面的代码但没有工作:

add_action ('__after_header' , 'add_content_after_header', 20);

function add_content_after_header() {
    //checks if we are displaying the home page
    if ( !tc__f( '__is_home' ) )
        return;
    ?>
        <div id="my-content-header">
        <p>Content</p>
        </div>
    <?php
}

然后我尝试了另一个代码,它正在工作但在标题顶部显示内容:

add_action ('wp_head' , 'add_content_after_header', 20);

function add_content_after_header() {
    //checks if we are displaying the home page
  global $post;
  if ($post->post_type == 'page' && $post->ID == '7')
        return;
    ?>
        <div id="my-content-header">
        <p>Content</p>
        </div>
    <?php
}

基本上“__after_header”操作对我不起作用,但“wp_head”操作显示标题顶部的内容。任何想法如何解决这个问题并将内容放在标题下方?

标签: phpwordpressheader

解决方案


推荐阅读