wordpress - “无法重新声明 post_redirect_by_custom_filters()”的任何解决方案?
问题描述
我正在使用下面的代码将一个类别的所有帖子重定向到其他域
add_action('template_redirect', 'post_redirect_by_custom_filters');
function post_redirect_by_custom_filters() {
global $post;
// this array can contain category names, slugs or even IDs.
$catArray = ['HW', '123x', '11x', '111x', '1111x'];
if (is_single($post->ID) && has_category($catArray, $post)) {
$new_url = "https://my2nddomain.com/{$post->post_name}/";
wp_redirect($new_url, 301);
exit;
}
}
但现在我想将某些类别的帖子重定向到我的第三个站点。但是当我在 funtion.php 中重用此代码时,我收到此错误 Cannot redeclare post_redirect_by_custom_filters() (之前在 wp-content/themes/poster/functions.php 中声明)
有什么解决方案吗?
解决方案
推荐阅读
- python - 添加到不带引号的python列表
- css - 如何用css反转wave svg?
- r - 将日期字符串转换为 R 中的天数
- android - 通过对话框将数据从适配器传递到活动
- c++ - 从 Select 调用返回后,在服务器上处理/重组 TCP 分段数据包的方法
- android-camerax - java.lang.IllegalArgumentException:建议的分辨率地图缺少相机 1 的分辨率
- r - R:将函数逐行应用于表,将查找表中的值作为参数传递
- java - 我的朋友指出[在 main 上抛出是不合适的]。我应该如何以及在哪里修复它?
- c# - 如何清理做几乎相同事情的长 if else 语句
- install4j - Bamboo 上 install4j5 到 install4j7 升级问题