You can use the single_template
filter to switch out the template. In your callback, see if the theme provided a template for the post type, if it did, do nothing.
1 2 3 4 5 6 7 8 9 10 11 | <?php add_filter('single_template', 'wpse96660_single_template'); function wpse96660_single_template($template) { if ('your_post_type' == get_post_type(get_queried_object_id()) && !$template) { // if you're here, you're on a singlar page for your costum post // type and WP did NOT locate a template, use your own. $template = dirname(__FILE__) . '/path/to/fallback/template.php'; } return $template; } |
Alternatively, you can use a callback with the_content filter, and just change stuff in the content itself.
1 2 3 4 5 6 7 8 9 10 11 12 | <?php add_filter('the_content', 'wpse96660_the_content'); function wpse96660_the_content($content) { if (is_singular('your_post_type') && in_the_loop()) { // change stuff $content .= '<p>here we are on my custom post type</p>'; } return $content; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.