php - 尝试更改永久链接时 Function.php 不起作用
问题描述
我对 WordPress 非常陌生,并且使用他们提供的基本模板。但现在我需要添加我自己的函数来改变永久链接-
www.example.com?c=123 to www.example.com/c/123
这是我的 function.php 文件,我最后添加了进行转换的函数,但没有任何反应,我总是得到 www.example.com?c=123 to become www.example.com/c?123
*这可能是我想念的非常简单的东西,因为这是我第一次编辑这个文件
<?php
/**
* Go functions and definitions
*
* @package Go
*/
/**
* Theme constants.
*/
define( 'GO_VERSION', '1.4.2' );
/**
* AMPP setup, hooks, and filters.
*/
require_once get_parent_theme_file_path( 'includes/amp.php' );
/**
* Core setup, hooks, and filters.
*/
require_once get_parent_theme_file_path( 'includes/core.php' );
/**
* Customizer additions.
*/
require_once get_parent_theme_file_path( 'includes/customizer.php' );
/**
* Custom template tags for the theme.
*/
require_once get_parent_theme_file_path( 'includes/template-tags.php' );
/**
* Pluggable functions.
*/
require_once get_parent_theme_file_path( 'includes/pluggable.php' );
/**
* TGMPA plugin activation.
*/
require_once get_parent_theme_file_path( 'includes/tgm.php' );
/**
* WooCommerce functions.
*/
require_once get_parent_theme_file_path( 'includes/woocommerce.php' );
/**
* Page Titles Meta functions.
*/
require_once get_parent_theme_file_path( 'includes/title-meta.php' );
/**
* Layouts for the CoBlocks layout selector.
*/
foreach ( glob( get_parent_theme_file_path( 'partials/layouts/*.php' ) ) as $filename ) {
require_once $filename;
}
/**
* Run setup functions.
*/
Go\AMP\setup();
Go\Core\setup();
Go\TGM\setup();
Go\Customizer\setup();
Go\WooCommerce\setup();
Go\Title_Meta\setup();
if ( ! function_exists( 'wp_body_open' ) ) :
/**
* Fire the wp_body_open action.
*
* Added for backwards compatibility to support pre 5.2.0 WordPress versions.
*/
function wp_body_open() {
// Triggered after the opening <body> tag.
do_action( 'wp_body_open' );
}
endif;
add_filter( 'query_vars', 'addnew_query_vars', 10, 1 );
function addnew_query_vars($vars)
{
$vars[] = 'c'; // c is the name of variable you want to add
return $vars;
}
function custom_rewrite_basic()
{
add_rewrite_rule('^c/([0-9]+)/?', '?c=$1', 'top');
}
add_action('init', 'custom_rewrite_basic');'
解决方案
推荐阅读
- c - 如何将某些前缀添加到文件中的行
- kotlin - Kotlin 的 runCatching..也等同于 try..finally 吗?
- jenkins - Jenkinsfile 根据值变量检查 env 文件是否存在
- python - 将pickle文件导入Pandas后如何获取列名
- ffmpeg - 中断并恢复长时间运行的 ffmpeg 编码
- angular - Angular:制作自定义 UI 库,如 Angular Material,每个模块都有不同的入口点
- javascript - 使用地图按范围日期差距格式化
- javascript - 将代码库从 Webpack 移植到 Rollup 时,某些类在本应出现时未导出的问题
- android - listOf() 未解析的引用
- java - 网页生成期间输入的不正确中和(“跨站点脚本”)