You need to run this code in an action hook rather than directly in the functions.php file. Take a look at the Action Reference page in the Codex and determine at which point you want this script to run. Whatever action you choose will end up looking something like this:
add_filter( 'template_include', 'check_page_template', 99 );
function check_page_template( $template ) {
if( is_page_template( 'template-flat.php' ) ) {
// other code
} else {
require_once(functions . '/shortcodes.php');
}
return $template;
}
Related Posts:
- Ajax call always returns 0
- Is it ok to use a function to output the text domain name in a wordpress theme
- How to override a function when isn’t at functions.php
- contactform7 remove tags with “wpcf7_autop false” from functions.php
- How to count number of functions attached to an action hook?
- Show modified time if post is actually modified
- ajax live search for post title
- Hourly Routine Not Firing ( wp_schedule_event() )
- How to get an array of menu items from the toolbar?
- Fatal error: Call to undefined function add_action() – an untouched problem
- echo or print_r in an admin function
- Display a function using AJAX
- Query children and parent title
- How to make unique add_filter to the_content of specific page template files – so each template gets its own addition
- Hide the Private prefix on one specific page
- Creating loop within functions.php
- Limit filter upgrader_post_install to a single plugin
- How to test for Super Admin
- Adding a class to tag list in a function
- creating shortcode to pull json array
- img width and height attributes being set by get_the_post_thumbnail
- echo get_post_meta()
- Replace menu links with # and add name to its li
- Custom function in My Custom Functions returning 403
- Retrieve tags data in post body
- Remove H1 / title / Underscore – without CSS
- Custom Static Links For Specific Menu Right Before/Next The wp_nav_menu Function now working
- functions.php How to add css/js depending on Template Name?
- Change template on the fly based on post parent selection
- Current path on page in functions.php
- How do you publish a draft on WordPress
- How can I recompile js file in dist folder?
- Show Primary Category first when I display post categories
- Wp_query function to search from product_title ‘OR’ product tags name
- Remove the product category module block from the Woocommerce product page
- Setting youtube size in functions.php
- Redirect to another page if the user is logged in when pressing again the login button on menu bar
- wp_get_archives custom function broken since upgrading to WP 3.7.1
- Remove category from url
- ‘Attempt to modify property of non-object’ warning
- Conditional functions.php on page template
- Accessing two databases wordpress
- Problem with comments_number()
- Functions when woocommerce isn’t installed
- How to get correct value from checked()?
- Dequeue script to prevent javascript event conflict on wordpress child theme
- While loop with an exception after a count is reached
- Return child theme url
- Redefine function arguments before rendering
- Enqueue script on every page except one
- Best way to handle lack of titles in microblogging
- Upgraded server now class My_Walker_Nav_Menu extends Walker_Nav_Menu not working
- Functions php shortcode for displaying main menu with no child items
- How to include any template using Shortcode fuction?
- Redirect to other page if login
- display a div on ervery site but not frontpage?
- first paragraph of the_content as meta description
- get_terms (or tax_query) for term of current post?
- Do we need to change our child function.php to require/include child dir files when we add an over-riding file.php into the child theme
- How to use get_posts() function in functions.php
- Child theme functions.php
- How to echo Widget Title in Custom Frontend-Template Box
- Redirect to post after publish or update a published post
- Page Template Won’t Load Correct CSS File
- WordPress show bad the php hour and date
- show all the posts thumbnails
- the_excerpt function not showing image
- How to display this meta data (an array) in form of a function (created with a custom write panel)?
- WordPress – using sessions?
- Use a filter for wp_robots to block CPT/feed/
- Trigger email alert if file downloaded
- Completely Disable WordPress RSS Feeds
- How to hide content on mobile in the functions.php file – woocommerce
- Order column custom date using pre_get_posts
- query_vars treat as single var from URL
- Running javascript without hooking wp_head
- Remove text after a dot and a colon in Woocommerce product title
- Selecting specific query for offset
- Enable CORS Request for hostname using IP address
- Show image after X para – center aligned
- Change default color scheme in twentyfifteen child theme?
- Restrict access if logged out except for homepage
- Add meta data in head from theme
- what is `get_section()` and how to use it?
- function replace_text for entire page
- DISABLE wordpress upgrade page
- How to echo the translated custom field?
- Only Show One Category Name Per Post
- Moving CDN jQuery to footer does not work?
- Pass max posts to Javascript
- update_usermeta don’t work
- WP supersize not displaying when different languages flags are selected
- wp_list_pages change of children and anchor of parent
- How do I make my child theme’s CSS update when I save it?
- Bulk set Post Title as Tag where Tag is Empty Function
- How to resize image from import image url?
- Vimeo video play button color function
- How to overwrite image if it already exists – WordPress, Gravity form
- Change TinyMCE undeline outpout
- Loading newest dependency javascript module file in functions.php