Tag Info

Hot answers tagged

3

Your problem is that you didn't wrap it in a callback, but executed it immediately when functions.php was loaded by core. By then the global $wp_query object isn't initialized fully and the is_category() etc. wrappers can't deliver what you are expecting them to do. So your if/else checks should be moved inside the callback like this: add_filter( ...


2

May be something is wrong on your page template file. Have your added page template name at top of the page like this: <?php /* Template Name: My Custom Page */ Try with this and check once again. You can check WordPress document for creating custom page template. Check this link: Page Templates


1

According to the Codex, your custom page template must have a header containing the name of the template. All page templates must be named in this way, or they will not appear in the "Template" dropdown. Here's an example, make sure your custom template has a header in this format: <?php /* Template Name: My Custom Page */ // Your custom page template ...


1

This is what I've always done. Not sure if you need both $wp_query and $post but it's always worked for me. Just put this in plugin-main-file.php /** * Add single template for events post type plugin */ function custom_template_events_post_type_plugin($single) { global $wp_query, $post; if ($post->post_type == "events"){ $template ...


1

function get_custom_post_type_template($single_template) { global $post; if ($post->post_type == 'events') { $single_template = dirname( __FILE__ ) . '/single-event.php'; } return $single_template; } add_filter( 'single_template', 'get_custom_post_type_template' ); Source Or you could use: add_filter( ...


1

One way is to have a single front-page.php and then using get_template_part(), to show different content based on user choice. Rough code: get_header(); $layout = get_option( 'front_page_layout', 'default' ); get_template_part( 'front-page', $layout ); get_footer(); After that you need to create a file for every layout, they should be called, something ...


1

It seems the problem was it wasn't recognizing it was a page in the first place and thus couldn't recognize if there was a template applied to it. Changed if (is_page_template('page-templates/page-nosidebar.php')) { to if (is_page() && !is_page_template('page-templates/page-nosidebar.php')) {


1

I think your big problem here is your use of underscores (_) in your page template names. According to the Handbook of Coding Standards Files should be named descriptively using lowercase letters. Hyphens should separate words. my-plugin-name.php Also, for best practices you should call your custom page templates page-whatever.php So for ...


1

Instead of having a page template for all of them, have a single page template and use get_template_part to pull in the parts unique to each page. So instead of: update_post_meta($new_page_id, '_wp_page_template', $page_filename); You'd have: update_post_meta( $new_page_id, '_wp_page_template', 'newpagetemplate.php' ); update_post_meta( $new_page_id, ...



Only top voted, non community-wiki answers of a minimum length are eligible