Creating a wordpress plugin where users can override templates

You have to write it yourself. Check out the way WP e-commerce does it: First, the function to “register” the theme files. function wpsc_register_theme_file( $file_name ) { global $wpec_theme_files; if ( !in_array( $file_name, (array)$wpec_theme_files ) ) $wpec_theme_files[] = $file_name; } And then the function to find a theme file: /** * Checks the active theme … Read more

Show template loaded

The following will show the current template file to logged in admins only. If you add to the top of your functions file, you should see this info as the first line. add_action(‘wp_head’, ‘show_template’); function show_template() { global $template; global $current_user; get_currentuserinfo(); if ($current_user->user_level == 10 ) print_r($template); } You will still need to follow … Read more

How do I add a template to a theme using a plugin?

Here is a fairly simple approach I was able to get working within a plugin. You’ll want to reference https://developer.wordpress.org/reference/hooks/theme_page_templates/ and https://developer.wordpress.org/reference/hooks/template_include/ as you review the code below. <?php //Add our custom template to the admin’s templates dropdown add_filter( ‘theme_page_templates’, ‘pluginname_template_as_option’, 10, 3 ); function pluginname_template_as_option( $page_templates, $theme, $post ){ $page_templates[‘template-landing.php’] = ‘Example Landing Page’; … Read more

Trying to manage templates on a blog with lots of custom taxonomies

Page templates can be stored within the page-templates or templates subdirectory within a theme, but this does not apply to custom post type or taxonomy templates. Fortunately, the template_include filter can be used to change the template that will be loaded. In the example below, template files are stored in the /theme-name/templates/ directory. /** * … Read more

How to set global variables in template page?

Anywhere in your script, you can define a global variable as follow: Using the superglobal $GLOBALS array. This array is predefined by PHP, and is available in all scopes. It’s an associate array, containing all global variables as a key-value pair. ie: the key will be the variable name, and value will be the value … Read more