Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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;
}
<?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/single-acme.php';
if ('acme-cpt' === get_post_type(get_the_ID())) {
if (file_exists($archiveTemplate)) {
return $archiveTemplate;
}
}
return $originalArchiveTemplate;
}
<?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...
}
<?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
You can’t perform that action at this time.