How can I load a page template from a plugin?

You can use the theme_page_templates filter to add templates to the dropdown list of page templates like this: function wpse255804_add_page_template ($templates) { $templates[‘my-custom-template.php’] = ‘My Template’; return $templates; } add_filter (‘theme_page_templates’, ‘wpse255804_add_page_template’); Now WP will be searching for my-custom-template.php in the theme directory, so you will have to redirect that to your plugin directory by … Read more

Creating custom blog page template the right way

Don’t forget that WordPress was primarily designed to be a blogging CMS, so when it comes to theme development, developers often opt for a non-standard approach in exchange for the potential for more features. Theme developers have three options when they approach this, one of which (#2 below) you mentioned. Directly edit the index.php to … Read more

What does is_page_template() compare against?

Your condition should be written like this: if (is_page_template(‘path/file.php’)) { // Do stuff } I believe the confusion is a result of two things: The docs refer to “name” ambiguously. Specifying “file name” would make the documentation much more clear. The code behind is_page_template() shows the get_page_template_slug() function at its core. This function actually returns … Read more

How to *remove* a parent theme page template from a child theme?

Overriding that template would be much easier than getting rid of it. Just the way logic goes. I make no claim it’s efficient idea (late here), but this would get it nuked from edit screen: add_action(‘admin_head-post.php’,’remove_template’); function remove_template() { global $wp_themes; get_themes(); $templates = &$wp_themes[‘Twenty Ten’][‘Template Files’]; $template = trailingslashit( TEMPLATEPATH ).’onecolumn-page.php’; $key = array_search($template, … Read more

Use a template file for a specific url without creating a page

You can just look at url, load the file and exit. That can be done when WordPress loaded its environment, e.g. on ‘init’. add_action(‘init’, function() { $url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH), “https://wordpress.stackexchange.com/”); if ( $url_path === ‘retail’ ) { // load the file if exists $load = locate_template(‘template-retail.php’, true); if ($load) { exit(); // just exit … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)