admin管理员组文章数量:1387295
I created a WP plugin which adds a CPT and allows user to select custom template.
It was working when I used an MVC design but when I moved to a new MVC style it doesn't output on frontend and seems also doesn't assign custom template to page!
I used the following hooks:
add_filter(
'theme_page_templates', array( $this, 'add_new_template' )
);
add_filter(
'quick_edit_dropdown_pages_args',
array( $this, 'register_project_templates' )
);
add_filter(
'wp_insert_post_data',
array( $this, 'register_project_templates' )
);
// Add your templates to this array.
$this->templates = array(
'api.php' => 'API',
'print_invoice.php' => 'Print Invoice',
'wpc-post.php' => 'custom Post',
'dashboard.php' => 'Dashboard',
);
// self::create_dashboard_page();
add_action('add_meta_boxes', array($this, 'meta_box_visibility'));
add_action('save_post', array($this, 'wporg_save_postdata'), 10, 2);
/* Filter the single_template with our custom function*/
add_filter( 'template_include', array($this, 'my_plugin_templates'));
add_filter(
'manage_dashboard_posts_columns',
array($this, 'custom_post_type_columns')
);
add_action(
'manage_dashboard_posts_custom_column',
array($this, 'custom_column_content')
);
I created a WP plugin which adds a CPT and allows user to select custom template.
It was working when I used an MVC design but when I moved to a new MVC style it doesn't output on frontend and seems also doesn't assign custom template to page!
I used the following hooks:
add_filter(
'theme_page_templates', array( $this, 'add_new_template' )
);
add_filter(
'quick_edit_dropdown_pages_args',
array( $this, 'register_project_templates' )
);
add_filter(
'wp_insert_post_data',
array( $this, 'register_project_templates' )
);
// Add your templates to this array.
$this->templates = array(
'api.php' => 'API',
'print_invoice.php' => 'Print Invoice',
'wpc-post.php' => 'custom Post',
'dashboard.php' => 'Dashboard',
);
// self::create_dashboard_page();
add_action('add_meta_boxes', array($this, 'meta_box_visibility'));
add_action('save_post', array($this, 'wporg_save_postdata'), 10, 2);
/* Filter the single_template with our custom function*/
add_filter( 'template_include', array($this, 'my_plugin_templates'));
add_filter(
'manage_dashboard_posts_columns',
array($this, 'custom_post_type_columns')
);
add_action(
'manage_dashboard_posts_custom_column',
array($this, 'custom_column_content')
);
Share
Improve this question
asked Apr 11, 2020 at 15:18
TarikTarik
1215 bronze badges
1 Answer
Reset to default 1Using the following code I was able to load the custom template.
public function register_hook_callbacks(){
// Enqueue Styles & Scripts.
add_action( 'wp_enqueue_scripts',
array( $this, 'enqueue_scripts' ) );
add_filter('template_include',
array( $this, 'view_project_template')
);
}
本文标签: themesCustom template with CPT doesn39t display on frontend
版权声明:本文标题:themes - Custom template with CPT doesn't display on frontend 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744563408a2612901.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论