I am building a plugin. I just want to create page template whenever i install plugin. Page template like full-width template. I have used codes after searching but not able to get success. So please help me.
Thanks in advance
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI am building a plugin. I just want to create page template whenever i install plugin. Page template like full-width template. I have used codes after searching but not able to get success. So please help me.
Thanks in advance
If what you want is to actually generate a page template when the plugin is activated, you can use something like this:
<?php
/**
* Plugin Name: Testtest
* Description: Ignore
* Version: 0.1
* Author: windyjonas
*/
function myplugin_activate() {
$buf = "<?php\n"
. "/*\n"
. " * Template Name: generated template\n"
. " */\n"
. "?>\n"
. "Hello world\n";
$handle = fopen( get_stylesheet_directory() . '/tpl-plugin.php', 'w' );
fwrite( $handle, $buf );
fclose( $handle );
}
register_activation_hook( __FILE__, 'myplugin_activate' );
This only works if the web server user has enough privileges to write to theme directory.
.=
?
Nov 1, 2013 at 5:05