This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('single_template', 'acmeIncludeSingleTemplate'); | |
/** | |
* Includes a custom, single template as included in a plugin. If | |
* the template is being viewed for a custom post type then use it; | |
* otherwise, use the template that's provided by WordPress at runtime. | |
* | |
* @param string $originalTemplate the path to the original template | |
* | |
* @return string the path to the original template or the custom template. | |
*/ | |
function acmeIncludeSingleTemplate($originalTemplate) | |
{ | |
$singleTemplate = plugin_dir_path( | |
\dirname( | |
__DIR__ | |
) | |
); | |
$singleTemplate .= '/templates/single-acme.php'; | |
if ('acme-cpt' === get_post_type(get_the_ID())) { | |
if (file_exists($singleTemplate)) { | |
return $singleTemplate; | |
} | |
} | |
return $originalTemplate; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('archive_template', 'acmeIncludeArchiveTemplate'); | |
/** | |
* Includes a custom, archive template as included in a plugin. If | |
* the template is being viewed for a custom post type then use it; | |
* otherwise, use the template that's provided by WordPress at runtime. | |
* | |
* @param string $originalArchiveTemplate the path to the original template | |
* | |
* @return string the path to the original template or the custom template. | |
*/ | |
function acmeIncludeArchiveTemplate($originalArchiveTemplate) | |
{ | |
$archiveTemplate = plugin_dir_path( | |
\dirname( | |
__DIR__ | |
) | |
); | |
$archiveTemplate .= '/templates/archive-acme.php'; | |
if ('acme-cpt' === get_post_type(get_the_ID())) { | |
if (file_exists($archiveTemplate)) { | |
return $archiveTemplate; | |
} | |
} | |
return $originalArchiveTemplate; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('single_template', 'acmeIncludeSingleTemplate'); | |
/** | |
* Includes a custom, single template as included in a plugin. If | |
* the template is being viewed for a custom post type then use it; | |
* otherwise, use the template that's provided by WordPress at runtime. | |
* | |
* @param string $originalTemplate the path to the original template | |
* | |
* @return string the path to the original template or the custom template. | |
*/ | |
function acmeIncludeSingleTemplate($originalTemplate) | |
{ | |
// More to come... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('archive_template', 'acmeIncludeArchiveTemplate'); | |
/** | |
* Includes a custom, archive template as included in a plugin. If | |
* the template is being viewed for a custom post type then use it; | |
* otherwise, use the template that's provided by WordPress at runtime. | |
* | |
* @param string $originalArchiveTemplate the path to the original template | |
* | |
* @return string the path to the original template or the custom template. | |
*/ | |
function acmeIncludeArchiveTemplate($originalArchiveTemplate) | |
{ | |
// More to come... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment