So I'm kinda stuck on something that I'm trying to achieve and unsure how to even target it, so below I will explain all that I have and what I have tried.
So I'm using the Genesis Framework and a child theme. I'm trying not to touch the Framework or the child theme, and do all the development inside mu-plugins but I'm having trouble targeting a custom template.
So I've created a custom post type that is linked as /profile/
so let's say I create a file called page-profile.php
, following WordPress hierarchy it will use my custom page first.
But how do I target a template that has a URL such as /profile/jake-ferguson/
where the author's name will be different each time?
So I'm kinda stuck on something that I'm trying to achieve and unsure how to even target it, so below I will explain all that I have and what I have tried.
So I'm using the Genesis Framework and a child theme. I'm trying not to touch the Framework or the child theme, and do all the development inside mu-plugins but I'm having trouble targeting a custom template.
So I've created a custom post type that is linked as /profile/
so let's say I create a file called page-profile.php
, following WordPress hierarchy it will use my custom page first.
But how do I target a template that has a URL such as /profile/jake-ferguson/
where the author's name will be different each time?
1 Answer
Reset to default 1If you're just trying to add a template within the theme, name your file single-profile.php
and that will apply to all single "profile" CPTs.
But you mentioned you don't want to touch the child theme. You could instead create a plugin and use a page_template
filter to use your plugin's single-profile.php
template instead of any of the theme templates.
You would create a plugin folder, put your single-profile.php
file in that folder, and add a plugin.php
file that contains something like
<?php
add_action('page_template', 'wpse_apply_profile_template');
function wpse_apply_profile_template() {
// If this is the CPT we're looking for
if(is_singular('profile')) {
// Apply this plugin's "single-profile.php" template
$page_template = dirname( __FILE__ . 'single-profile.php';
}
// Always return, even if we didn't change the template
return $page_template;
}
?>