admin管理员组

文章数量:1291010

I am trying to add custom metaboxes to only those pages that use a certain custom template that is applied to them.

How can i do this? I based on this this guide: How to add add_meta_box to specific Page Template?

But it doesn't work for me. How come?

This is my code in functions.php:

add_action("admin_init", "metabox_bookmaker");
function metabox_bookmaker(){
    global $post;
    if ( 'page-templates/template-bookmaker.php' == get_post_meta( $post->ID, '_wp_page_template', true ) ) {
        add_meta_box("metabox_bookmaker_custom", "Metabox per Single Bookmaker", "custom_metabox_bookmaker", "page", "normal", "high");
    }
}

本文标签: Add metabox to pages that use custom template in WordPress