【问题标题】:WordPress only apply funtion on front pageWordPress 只在首页应用功能
【发布时间】:2022-07-15 04:40:40
【问题描述】:

我在functions.php 中放置了以下最小的 PHP 代码,它可以工作。

add_action( 'init', 'test' );

function test() {
   echo 'Testing...123';
}

但是如果我用is_front_page()指定只在首页应用这个(front-page.php),那就不行了,为什么会这样呢?

if ( is_front_page() ) {
   add_action( 'init', 'test' );

   function test() {
      echo 'Testing...123';
   }
}

【问题讨论】:

  • 在您的 WP 设置中,您是否将特定页面设置为静态首页?如果没有,front-page.php 永远不会被引用。

标签: wordpress


【解决方案1】:

尝试将其更改为以下内容

add_action( 'init', 'test' );

function test() {
    if ( is_front_page() ) {
      echo 'Testing...123';
   }
}

【讨论】:

    猜你喜欢
    • 2013-02-26
    • 2019-10-23
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-12
    • 1970-01-01
    相关资源
    最近更新 更多