You should not declare functions in your templates. The templates are for outputting content. The function_exists()
will check if the function is declared before the function_exists()
call, not after it, and templates are loaded after functions.php
file, since you can control them by using the template_redirect
filter.
Declare your function in your theme’s functions.php
file, and then call it in your template. This is the best way to go.
Related Posts:
- Php string not working in WordPress Functions.php (trying to fetch 1st category for each blog that post appears in the sidebar)
- How do you completely remove the default header and footer using functions.php?
- Where does function_exists() look to decide whether a function exists? [closed]
- Add external js file to footer with id
- Move jQuery and Migrate to footer?
- Twenty Eleven Child theme error when attempting to use a rewritten function
- how to add an image to the footer?
- How can I change the do_action function in footer (copyright area)
- Activate small php condition at footer over page template
- wp_register_script(… $in_footer = true) not working
- Override a theme function in a child theme?
- How to load jQuery in the footer – nothing works for me
- Which function required?
- wp_star_rating() – Adding a 5 star rating system to theme
- Insert nofollow in a “Powered By” link, except in the homepage [closed]
- I have an fatal error on my funcyions.php
- wp_footer hook causing text to show on bottom of page
- Providing fallback function and allow override by plugin
- Moving CDN jQuery to footer does not work?
- Retrieve array of attachment IDs attached to a given Post ID
- shortcode inside post called by ID does not render as expected
- Adding a second email address to a completed order in WooCommerce [closed]
- Possible to search by author name with default WordPress search function?
- Advantages and disadvantages of using automatic-feed-links
- Influence of WordPress functions on site speed
- Is it possible to override this function/class in a child theme?
- When new user register then add new user role
- Change meta tags programatically
- Convert hyphen to underscore in permalinks
- Remove bulk actions based on user role or capabilities
- Set first oembed in post to a global variable or function
- Adding extra SVGs to TwentyNineteen child theme using class TwentyNineteen_SVG_Icons
- Use a function to update post meta based on other post meta
- wp_delete_attachment
- Adding body class when post contains a specific shortcode
- Displaying Widgets
- WordPress registration and contact form 7 [closed]
- Display WooCommerce subscriptions for user [closed]
- Increment price for Woocommerce Minicart [closed]
- My simple custom shortcode is not longer working (possibly due to upgrade to WordPress 4.4 ?)
- PHP files included in functions.php don’t seem to work
- Removing the main link to Jetpack from the menu
- How To Remove Duplicate Menu Locations
- Redeclare theme’s function in a plugin
- Show top commenters without using a plugin
- WordPress shortcode attributes for database SELECT?
- How to get membership level for specific user email
- Post thumbnail not showing in WP admin area for custom post type
- Backstretch.js and thumbnail sizes to reduce loading time
- Child theme within a child theme?
- Fatal error: Cannot redeclare when switching themes
- Featured Image Thumbnail Creation
- How do display most popular post from a year earlier to the day?
- Updating Media Published Date When Parent Post Is Modified in WordPress
- WP Ajax Function Always Returning undefined
- How can I grab the video id of youtube?
- Specify number of posts for sub-category page
- Creating A New Admin Menu Tab For Theme Options
- Passing variable as add_shortcode argument
- Run wp_kses_decode_entities on atom feed?
- comments_popup_link without echo?
- Can’t filter wp_get_attachment_link
- Function extending with if query in functions.php
- add_action wp_enqueue_script priority level only works for admins
- current_user_can comma list vs OR (||) list
- Include the post type before the title of search results
- What is wrong with code added to functions.php to selectively show styles based on login state
- Writing a function to detect an event
- Problem with calling custom function in a foreach loop
- The_content and Preg_replace in loaded Iframe [closed]
- dynamic site link for future migration in echo do_shortcode()
- Hide tab Buddypress profile for visitors, not logged in users
- WooCommerce -> wc_enqueue_js not working [closed]
- Use existing image sizes for WooCommerce
- Add a mature content warning to first-time visitors
- Show Featured Image in else statement
- Any adverse effects of adding apply_filters to a function?
- How can I remove page titles without removing the link in the navigation bar in twentyeleven?
- Simplest Way to Build Custom Archives Page?
- Filter for replacing the WP_query object for a given category
- Custom user role still showing up after deletion, ideas?
- wordpress built-in Jalali date convertor
- WordPress Function Assistance with Loop
- Populate acf-field, depending on block name
- Add Change role button for list of user in an event
- I am trying to set post terms to a custom taxonomy
- Classic TinyMCE messing up only Contributor’s HTML
- Reference multiple style sheets, clearing styles for permalink page, custom fields for css
- Add schema to Search result page’s body. Tried using is_search
- Disable links to images only if link is an image
- WordPress Javascript Widget jQuery Dependency Issue
- Open image size links in a page instead of direct image link
- Allow tags and attributes in post and pages content
- Function to get thumbnail img source
- Syntax for a function in order to get post’s title in JSON encoded response [closed]
- Comment Function
- Do something when user creates post (that’s pending)
- Will my WordPress site become vulnerable after adding this functions which allows more HTML tags for subscribers?
- Add product to cart from functions.php
- How to overwrite image if it already exists – WordPress, Gravity form