最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp admin - Change link for "add new" buttons on custom post type

programmeradmin2浏览0评论

I know how to use capabilities to remove the "Add New" functionality for a custom post type, but what I really need to do is change the target of those links. Does anyone know how I might go about doing that?

I would be an "external" link (to the front end of the website) and not a page on wp-admin.

I know how to use capabilities to remove the "Add New" functionality for a custom post type, but what I really need to do is change the target of those links. Does anyone know how I might go about doing that?

I would be an "external" link (to the front end of the website) and not a page on wp-admin.

Share Improve this question asked Jun 25, 2017 at 16:17 EcksteinEckstein 1,1194 gold badges27 silver badges52 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

in most of the case WordPress ui uses admin_url() function to retrieve administrative urls. so you can use admin_url filter to modify that.

Example:

add_filter( 'admin_url', 'wpse_271288_change_add_new_link_for_post_type', 10, 2 );
function wpse_271288_change_add_new_link_for_post_type( $url, $path ){
    if( $path === 'post-new.php?post_type=your_custom_post_type' ) {
        $url = get_permalink(/*your post ID here*/); // or any other url
    }
    return $url;
}

Change your_custom_post_type with your custom post type name.

Reference (WordPress Version 4.8): edit.php (Line No. 312) and link-template.php (Line No. 3132)

发布评论

评论列表(0)

  1. 暂无评论