php - 困惑如何在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 );
但具体在哪里?
解决方案
我不完全确定您希望 add_filter 运行什么/何时运行。如果它应该在您调用functions.php 时运行,请将其添加到末尾的?> 之前(这标志着PHP 代码的结束,开头通常看起来像<?php)。但是,如果您只希望它在设置了 $_GET['activated'] 时运行,则需要在 } 上方的一行中使用它。
抱歉,我无法提供更多帮助,我不熟悉 WordPress。
推荐阅读
- r - 如何在R中构造一个螺旋矩阵?
- angular - 如何清除primeng多选中的搜索文本框
- django - Django Guardian - 在过滤期间检查权限
- c# - 如何在日历控件中预先选择多个月份 - WPF
- css - 如何将 v-btn 与 v-expansion-panels 放在同一行?
- angular - CloudFront 上用于 Angular 应用程序的“NoSuchKey”代码
- ruby - 通过并行分配迭代哈希列表
- r - R & ggplot2 - 如何用二进制变量绘制分类分割的相对频率
- postgresql - 将动态数量的参数传递给函数的数组错误
- database - 获取两个日期之间的 HQL 查询记录