I want to include different file in function.php file of my wordpress theme based on different custom post type using admin_init hook. Is it possible?
I found the solution and added as an answer.
I want to include different file in function.php file of my wordpress theme based on different custom post type using admin_init hook. Is it possible?
I found the solution and added as an answer.
add_action('admin_init', 'include_files');
function include_files()
{
global $pagenow;
if ('post.php' == $pagenow && isset($_GET['post']) )
{
$post_type = get_post_type(esc_attr($_GET['post'])) ;
}
else if ('post-new.php' == $pagenow && isset($_GET['post_type']) )
{
$post_type = $_GET['post_type'];
}
if($post_type == 'custom_post'){
include_once('file1.php');
}else{
include_once('file2.php');
}
}