我想在文件wp();
的{{1}}行之后运行一个函数,在这里使用正确的wp-blog-header.php
是什么?
hook
我们正在迁移到新网站,我们必须关心旧的URL,所以我做了什么:
<?php
/**
* Loads the WordPress environment and template.
*
* @package WordPress
*/
if ( !isset($wp_did_header) ) {
$wp_did_header = true;
// Load the WordPress library.
require_once( dirname(__FILE__) . '/wp-load.php' );
// Set up the WordPress query.
wp();
/********************************************
I WANT TO RUN THE FUNCTION AT THIS POINT
********************************************/
// Load the theme template.
require_once( ABSPATH . WPINC . '/template-loader.php' );
}
配置文件中添加了以下rewrite
规则: NGINX
此规则将向URL(旧URL)添加一个额外的参数rewrite \D+(\/\d+\/\D+)$ /index.php?redirect=$1 break;
,该参数的值将用于获取新的最终URL。
redirect
与最终URL redirect_from
映射)获得最终URL:< / li>
redirect_to
注意: 无法从旧网址中获取新网址,这是旧网址和新网址的示例:
重定向自:
/**
* 1. Check if the URL has a parameter [redirect]
* 2. If NO, proceed to the next step
* 3. If YES, then get that parameter value and look into [redirects] table
* 4. If you found a row that has that value, then get the [redirect_to] value
* 5. Redirect to that URL [redirect_to]
*/
if (isset($_GET['redirect'])) {
// Get the parameter value from the URL
$redirect_from = $_GET['redirect'];
// Add the table prefix to the table name
$table_name = $wpdb->prefix . 'redirects';
// The SQL query
$query = "
SELECT redirect_to
FROM $table_name
WHERE redirect_from = '$redirect_from';
";
// Run the SQL query and get the results
$result = $wpdb->get_results($query, OBJECT);
// If there was a result then do the redirection and exit
if (wp_redirect($result[0]->redirect_to)) {exit;}
}
收件人:
http://www.example.com/category/sub-category/post-id/slug