首页 > 解决方案 > 困惑如何在functions.php文件的结束标记之前添加此代码

问题描述

我的函数 php 文件这样结束

//Setup custom settings when theme is activated

if (isset($_GET['activated']) && $_GET['activated']){

//Add default contact fields

$pp\_contact\_form = get\_option('pp\_contact\_form');

if(empty($pp\_contact\_form))

{

    add\_option( 'pp\_contact\_form', 's:1:"3";' );

}



$pp\_contact\_form\_sort\_data = get\_option('pp\_contact\_form\_sort\_data');

if(empty($pp\_contact\_form\_sort\_data))

{

    add\_option( 'pp\_contact\_form\_sort\_data', 'a:3:{i:0;s:1:"1";i:1;s:1:"2";i:2;s:1:"3";}' );

}


wp\_redirect(admin\_url("admin.php?page=functions.php&activate=true"));
}

?>

我需要在 functions.php 文件的结束标记之前添加以下代码:

add_filter( 'gettext', function ( $strings ) { /** * Holding translations/changes. * 'to translate' => 'the translation or rewording' */ $text = array( 'Any Brand' => 'Any Brands', 'Any Type'=>'Any Types', 'Search'=>'Searches' ); $strings = str_ireplace( array_keys( $text ), $text, $strings ); return $strings; }, 20 );

但具体在哪里?

标签: phpfunction

解决方案


我不完全确定您希望 add_filter 运行什么/何时运行。如果它应该在您调用functions.php 时运行,请将其添加到末尾的?> 之前(这标志着PHP 代码的结束,开头通常看起来像<?php)。但是,如果您只希望它在设置了 $_GET['activated'] 时运行,则需要在 } 上方的一行中使用它。

抱歉,我无法提供更多帮助,我不熟悉 WordPress。


推荐阅读