php版本升级到8.3后,page页面别名(slug)调用发生如下错误:

Warning: Undefined variable $post in /www/wwwroot/wodepress.com/wp-content/themes/x/functions.php on line 94

Warning: Attempt to read property "ID" on null in /www/wwwroot/wodepress.com/wp-content/themes/x/functions.php on line 94

解决这个问题的方法

1、先在主题文件夹x中找functions.php文件

2、在functions.php文件中找到

function the_slug() {
$post_data = get_post($post->ID, ARRAY_A);
$slug = $post_data['post_name'];
return $slug; 
}

3、将上面的代码替换成

function the_slug() {
global $post;
$post_data = get_post($post->ID, ARRAY_A);
$slug = $post_data['post_name'];
return $slug; 
}

即可解决这个问题