admin管理员组

文章数量:1302318

Which hooks can I use to add my own HTML stuff to a CPT edit screen? I created an own CPT with

$args = array (
    'labels' => array (
        'name'          => 'Catalog',
    ),
    'capability_type'   => 'post',
    'has_archive'       => true,
    'public'            => true,
    'show_in_menu'      => true,
    'rewrite'           => array ( 
        'slug'  => 'catalog' 
    ),
    'supports' =>   array (
        'title', 
        'thumbnail' 
    ),
);

register_post_type( 'catalog', $args );

I use only the featured image for the rest I removed all default things like title editor... You can see this in the support array in my code above.

Now I want add my own HTML stuff to this editpage

Which hooks can I use to add my own HTML stuff to a CPT edit screen? I created an own CPT with

$args = array (
    'labels' => array (
        'name'          => 'Catalog',
    ),
    'capability_type'   => 'post',
    'has_archive'       => true,
    'public'            => true,
    'show_in_menu'      => true,
    'rewrite'           => array ( 
        'slug'  => 'catalog' 
    ),
    'supports' =>   array (
        'title', 
        'thumbnail' 
    ),
);

register_post_type( 'catalog', $args );

I use only the featured image for the rest I removed all default things like title editor... You can see this in the support array in my code above.

Now I want add my own HTML stuff to this editpage

Share Improve this question edited Mar 20, 2021 at 19:10 Jop asked Mar 19, 2021 at 23:16 JopJop 1279 bronze badges 5
  • are you referring to the classic editor or the block editor? – Tom J Nowell Commented Mar 19, 2021 at 23:40
  • @TomJNowell the classic editor – Jop Commented Mar 19, 2021 at 23:41
  • What exactly are you trying to do that requires this? What's the context? – Tom J Nowell Commented Mar 20, 2021 at 12:44
  • With my own HTML I have more control. I want create my own form and I don't need the default input fields. I thought it was easy to do just like a calback page for add_admin_menu. – Jop Commented Mar 20, 2021 at 18:41
  • So you don't just want to add things, you want to remove things too? I ask this because there are multiple hooks and filters, but which one to use depends on what you want to do. By keeping your answer as generic as possible you make the question much harder to answer. People answering would have to write a comprehensive answer that covers every possible use case for every possible situation, which could take hours. Add more context and be more specific in your question, state what you are trying to replace, and what you're replacing it with – Tom J Nowell Commented Mar 20, 2021 at 18:52
Add a comment  | 

1 Answer 1

Reset to default 0

I found a solution

add_action('edit_form_advanced', 'add_to_admin_cpt');

function add_to_admin_cpt() {
    global $post;
    if ($post->post_type == 'catalog') {
        //doing my own stuff
    }
}

本文标签: custom post typesAdd html tot CPT edit screenno metabox