Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. add_action( 'wp_loaded', 'add_my_templates' );
  2. function add_my_templates(){
  3. if( is_admin() ){
  4. global $wp_object_cache;
  5. $current_theme = wp_get_theme();
  6. $templates = $current_theme->get_page_templates();
  7. $hash = md5( $current_theme->theme_root . '/'. $current_theme->stylesheet );
  8. $templates = $wp_object_cache->get( 'page_templates-'. $hash, 'themes' );
  9. $templates['templates/exams.php'] = __('Exams');
  10. $templates['templates/colleges.php'] = __('Colleges');
  11. $templates['templates/study_home.php'] = __('Study Home');
  12. $templates['templates/study_job_home.php'] = __('Study Job Home');
  13. wp_cache_replace( 'page_templates-'. $hash, $templates, 'themes' );
  14. }
  15. else {
  16. add_filter( 'page_template', 'get_my_template', 1 );
  17. }
  18. }
  19.  
  20. function get_my_template( $template ){
  21. $post = get_post();
  22. $page_template = get_post_meta( $post->ID, '_wp_page_template', true );
  23. if( $page_template == 'templates/study_home.php' ){
  24. $template = plugin_dir_path(__FILE__) . "templates/study_home.php";
  25. }
  26. if( $page_template == 'templates/study_job_home.php' ){
  27. $template = plugin_dir_path(__FILE__) . "templates/study_job_home.php";
  28. }
  29. if( $page_template == 'templates/exams.php' ){
  30. $template = plugin_dir_path(__FILE__) . "templates/exams.php";
  31. }
  32. if( $page_template == 'templates/colleges.php' ){
  33. $template = plugin_dir_path(__FILE__) . "templates/colleges.php";
  34. }
  35. return $template;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement