If you’re hoping to override CORE template files via your plugin, the plugin uses a filter which gives you that opportunity.
return apply_filters( 'job_manager_locate_template', $template, $template_name, $template_path );
Filter job_manager_locate_template, check what $template_name is being filtered and return the updated path.
Yes, I want to override core template files from wp job manager. I read this post: https://wordpress.org/support/topic/template-overrides-via-plugin
, but I really need an example how to write the filter.
The only thing I need is to have a template folder in my plugin directory which works like the folder in the theme directory.
The filter I posted is what you need. If you’ve written a plugin, surely you’re familiar with filter syntax? Basic example:
add_filter( 'job_manager_locate_template', 'custom_job_manager_locate_template', 10, 3 );
function custom_job_manager_locate_template( $template, $template_name, $template_path ) {
return 'somenewtemplatepath';
}
Finally, I got it to work with this filter (it tries to load each template from my plugin’s folder, but if there is no custom template, it will use the original one.)
add_filter( 'job_manager_locate_template', 'custom_job_manager_locate_template', 10, 3 );
function custom_job_manager_locate_template( $template, $template_name, $template_path ) {
$plugin_path = dirname(__FILE__) . '/templates/' . $template_name;
if (file_exists($plugin_path))
return $plugin_path;
else
return $template;
}
But there is a problem again. It seems like this filter only filters the “job-filters”-templates, but not the “content”-templates. (I use the [jobs] shortcode). Could you test my filter and find the reason why it does not work as expected?
Those ones are not filtered. Log an issue on github.