admin管理员组文章数量:1415146
I wanted to know do i group my custom post types to appear together in a group in the wordpress back end menu bar like this below in the picture what code do i have to use in my functions.php so that i can give my custom post types a nice look and feel:
Currently I am using a custom plugin to add functions and it looks like this
<?php
/**
* Plugin Name: Custom Functions
* Plugin URI: http://localhost/
* Description: This is an awesome custom plugin with functionality that I'd like to keep when switching Themes.
* Author: Phantom.omaga
* Version: 0.1.0
*/
/* Place custom code below this line. */
add_action( 'init', 'create_post_type' );
function create_post_type() {
/*Custom post type Series has been decleared here*/
register_post_type( 'series',
array(
'labels' => array(
'name' => __( 'Series' ),
'singular_name' => __( 'Series' )
),
'public' => true,
'menu_position' => 40,
'rewrite' => array('slug' => 'Series')
)
);
/*Custom post type Episodes has been decleared here*/
register_post_type( 'epsodes',
array(
'labels' => array(
'name' => __( 'Episodes' ),
'singular_name' => __( 'Episode' )
),
'public' => true,
'menu_position' => 41,
'rewrite' => array('slug' => 'Episodes')
)
);
/*Custom post type Mirrors has been decleared here*/
register_post_type( 'Mirrors',
array(
'labels' => array(
'name' => __( 'Mirrors' ),
'singular_name' => __( 'Mirror' )
),
'public' => true,
'menu_position' => 41,
'rewrite' => array('slug' => 'Mirror')
)
);
}
/* Place custom code above this line. */
?>
I wanted to know do i group my custom post types to appear together in a group in the wordpress back end menu bar like this below in the picture what code do i have to use in my functions.php so that i can give my custom post types a nice look and feel:
Currently I am using a custom plugin to add functions and it looks like this
<?php
/**
* Plugin Name: Custom Functions
* Plugin URI: http://localhost/
* Description: This is an awesome custom plugin with functionality that I'd like to keep when switching Themes.
* Author: Phantom.omaga
* Version: 0.1.0
*/
/* Place custom code below this line. */
add_action( 'init', 'create_post_type' );
function create_post_type() {
/*Custom post type Series has been decleared here*/
register_post_type( 'series',
array(
'labels' => array(
'name' => __( 'Series' ),
'singular_name' => __( 'Series' )
),
'public' => true,
'menu_position' => 40,
'rewrite' => array('slug' => 'Series')
)
);
/*Custom post type Episodes has been decleared here*/
register_post_type( 'epsodes',
array(
'labels' => array(
'name' => __( 'Episodes' ),
'singular_name' => __( 'Episode' )
),
'public' => true,
'menu_position' => 41,
'rewrite' => array('slug' => 'Episodes')
)
);
/*Custom post type Mirrors has been decleared here*/
register_post_type( 'Mirrors',
array(
'labels' => array(
'name' => __( 'Mirrors' ),
'singular_name' => __( 'Mirror' )
),
'public' => true,
'menu_position' => 41,
'rewrite' => array('slug' => 'Mirror')
)
);
}
/* Place custom code above this line. */
?>
Share
Improve this question
edited Aug 25, 2019 at 16:52
Jan Doggen
16911 bronze badges
asked Oct 29, 2011 at 6:18
phantom.omagaphantom.omaga
5582 silver badges15 bronze badges
1 Answer
Reset to default 5The filter
Inside /wp-admin/menu.php, you'll find this filter at the end of the "add css classes"-loop:
apply_filters( 'add_menu_classes', $menu )
The function
The following code attaches the right classes to the first and previous elements. It also adds the separator in between. If you need to add another separator to the end/after your group, you'll have to extend the function to do the following:
- Take the last element in your group and treat it exactly as you currently treat your previous element.
- Add the separator one key after your last element
- Add the same classes to the following/next element right after your group
- Check if there's not already a separator in place. See current check.
Use the $target
array to look up for the names of the targeted menu elements. Just use exactly what you see in your menu and it adds a separator before the element.
Moved the code to GitHub as public Gist
本文标签: functionshow to group custom post types
版权声明:本文标题:functions - how to group custom post types 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745216445a2648193.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论