Php 奇怪的问题改变后标签

Php 奇怪的问题改变后标签,php,wordpress,Php,Wordpress,因此,我使用此代码将帖子更改为“Mentor Q&a”作为标签,但是函数返回了一个奇怪的错误 分析错误:语法错误,意外的“$menu”(T_变量). 这是我正在尝试运行的函数: function change_post_label() {     global $menu;     global $submenu;     $menu[5][0] = 'Mentor Q&A';     $submenu['edit.php'][5][0] = 'Mentor Q&A';     

因此,我使用此代码将帖子更改为“Mentor Q&a”作为标签,但是函数返回了一个奇怪的错误

分析错误:语法错误,意外的“$menu”(T_变量).

这是我正在尝试运行的函数:

function change_post_label() {
    global $menu;
    global $submenu;
    $menu[5][0] = 'Mentor Q&A';
    $submenu['edit.php'][5][0] = 'Mentor Q&A';
    $submenu['edit.php'][10][0] = 'Add Mentor Q&A';
    $submenu['edit.php'][16][0] = 'Mentor Q&A Tags';
    echo '';

function  change_post_object() {
    global $wp_post_types;
    $labels = &$wp_post_types['post']->labels;
    $labels->name = 'Mentor Q&A';
    $labels->singular_name = 'Mentor Q&A';
    $labels->add_new = 'Add Mentor Q&A';
    $labels->add_new_item = 'Add Mentor Q&A';
    $labels->edit_item = 'Edit Mentor Q&A';
    $labels->new_item = 'Mentor Q&A';
    $labels->view_item = 'View Mentor Q&A';
    $labels->search_items = 'Search Mentor Q&A';
    $labels->not_found = 'No Mentor Q&A found';
    $labels->not_found_in_trash = 'No Mentor Q&A found in Trash';
    $labels->all_items = 'All Mentor Q&A';
    $labels->menu_name = 'Mentor Q&A';
    $labels->name_admin_bar = 'Mentor Q&A';
}
 
add_action( 'admin_menu', 'change_post_label' );
add_action( 'init', 'change_post_object');

这个函数也在子主题的functions.php中被调用,我不确定这是否与此有关。

我觉得函数应该正确关闭

function change_post_label() {
  global $menu;
  global $submenu;
  $menu[5][0] = 'Mentor Q&A';
  $submenu['edit.php'][5][0] = 'Mentor Q&A';
  $submenu['edit.php'][10][0] = 'Add Mentor Q&A';
  $submenu['edit.php'][16][0] = 'Mentor Q&A Tags';
  echo '';
}

解决了。问题是,我从中复制的代码中的缩进是实际的空格,这使得代码无效,doh


吸取的教训。

joshy,函数更改\u post\u label(){未正确关闭如果复制代码,请确保仔细检查;)