首页 > 解决方案 > 尝试更改永久链接时 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');'

标签: phpwordpressurlget

解决方案


推荐阅读