WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to know: I have wrote at 60% one plugin, it works well in backend (some settings, some cpt, some custom fields... nothing special). It uses custom post type with custom fields.

For now I need to change default archive category behaviour as well as change behaviour of single posts of this CPT _doesn't_touching_ templates (because this plugin will be used not only in the 1 site and there will be many templates).

Just programmatically, by filters/actions - change it as I like.. for example, I will need to show up this custom fields in this single custom post type.

Does somebody knows about how to do it by plugin?

share|improve this question
Could you provide some concrete examples? I am not sure I understood what you want to achieve. – toscho Oct 7 '12 at 22:54
Okay, let's see if this sounds right: you want to be able to programmatically display the custom fields and types on the front end using plugin files instead of theme files? I know the Organize Series plugin does this. I can dig through its code if that's the kind of thing you're looking for. – Liana Mir Oct 9 '12 at 17:30

You can use templates located within your plugin instead of theme files, like so:

add_filter('archive_template', 'redirect_to_plugin_archive_template');
function redirect_to_plugin_archive_template($template) {

    if(is_post_type_archive('my_cpt')) {
        return dirname(__FILE__) . '/templates/my_archive_template.php';

add_filter('single_template', 'redirect_to_plugin_single_template');
function redirect_to_plugin_single_template($template) {

    if(is_singular('my_cpt')) {
        return dirname(__FILE__) . '/templates/my_single_template.php';

Obviously you need to change the custom post type slug and the template paths, but that's the general idea.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.