更改帖子标签的奇怪问题

时间:2014-08-29 10:59:53

标签: php wordpress

所以我使用此代码将帖子更改为'Mentor Q& A'作为标签,但该函数返回一个奇怪的错误

Parse error: syntax error, unexpected '$menu' (T_VARIABLE) ...

这是我正在尝试运行的功能:

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中调用,我不确定它是否与它有任何关系。

2 个答案:

答案 0 :(得分:0)

我认为功能应该正确关闭

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 '';
}

答案 1 :(得分:0)

解决。问题是我复制的代码中的缩进(如果是)是使代码无效的实际空格,doh!

经验教训。

相关问题