Search code examples
phpwordpresstemplates

Developing a wordpress template generation through a plugin


I am developing a wordpress plugin which generates a team page. So i need to add a template page team.php. Can the process be automated independent of the theme, or the user have to be urged for copying the file manually to the templates directory.


Solution

  • You shouldn't need to copy the page like that. Ask the user to create a normal page with only a shortcode in it which you can replace with you content.

    That's the standard way to do these things. This page will tell you how to do it : http://codex.wordpress.org/Shortcode_API

    Example :

    //In your functions.php file
    function create_team_page($atts, $content = null){
        //$team_data = generate data here 
        return $team_data;
    }
    add_shortcode('team_page', 'create_team_page');
    

    The user would simply create a new page with wordpress and put the shortcode [team_data] in the contents. Your hook would replace it with content.