How to make my plugin theme-independent?

I need a little help and/or consulting for my next steps. (I’m a beginner!)

I’ve been working on my plugin, using a Custom Post Type “Project”, some help from the plugin “Advanced Custom Fields” – and now I have succeeded in the general functionality.
Have a look at the images here and http://www.project22.org/project/ to see the functionality.
I admit, there might be plugins doing something similar, but I’m not advanced enough yet to understand and adjust their code to my specific needs ;(.

Read More

I worked within a child theme of Twentytwelve and needed to work with some template files, e.g. I created single-project.php and project_loop.php to use with get_template_part().

Problem:

  • I’m not so happy with Twentytwelve anymore – I’d like to retain some flexibility in changing my themes.
  • Maybe one day I want to share my plugin with someone, who knows?

So now my aim is to move all parts of the functionality into a plugin …

Questions:

  • How can I display these little pieces of information related to various posts on any theme? I couldn’t find appropriate hooks nor filters.
  • How can I avoid creating theme template files, which might later screw up new themes?

I’m really confused, where I should use []-Shortcodes, create template files or snippets, where I can hook or filter into.

I appreciate any advice from you,
thanks
Flo

Related posts

1 comment

  1. Shortcode is definitely a good start. It is very flexible in terms of where you output the content (widget, post, page, inside php function, etc).

    You can also override the template output easily by using action hooks and custom post type that you create:

    add_action('the_content', 'add_project_content');
    
    function add_project_content($content) {
        // Only override the content of project custom post type page
        if (is_singular('project')) {
            // You can re-use original content stored in $content and simply add things before and after, or you can simply override them with something new
            $content = "whatever you want";
            $content .= somefunction_output();
        };
    
        return $content;
    }
    

    This will lift you up from having to deal with template files and worry about matching changes for theme updates. With these methods I get away with creating any extra template files in my child theme folder.

Comments are closed.