Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <?php
  2. /*
  3. * 1. Go to Settings > Permalinks and select any page as home page
  4. * Then use the following code
  5. *
  6. * You can add those codes in your functions.php in the theme, if you think your theme won’t be changed.
  7. * Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'.
  8. * If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that,
  9. * give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins,
  10. * so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.
  11. *
  12. * Just change the correct CPT name
  13. */
  14.  
  15. add_action("pre_get_posts", "custom_front_page");
  16. function custom_front_page($wp_query){
  17. if(is_admin()) return;
  18.  
  19. if($wp_query->get('page_id') == get_option('page_on_front')){
  20.  
  21. $wp_query->set('post_type', 'CUSTOM POST TYPE NAME HERE');
  22. $wp_query->set('page_id', ''); //Empty
  23.  
  24. $wp_query->is_page = 0;
  25. $wp_query->is_singular = 0;
  26. $wp_query->is_post_type_archive = 1;
  27. $wp_query->is_archive = 1;
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement