It’s a timing issue. This tries to call is_home()
before that function exists.
$my_ver = check_home();
It works in the function called by add_action
because then is_home()
does exist because WP has fully loaded.
If you load php files in your plugin, then you can call check_home
anytime in those files.
For example:
define( 'MY_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
function ab_load_files() {
require( MY_PLUGIN_PATH . '/ab-functions.php' );
}
add_action( 'init', 'ab_load_files' );
Then this code will work if placed in ab-functions.php
$my_ver = check_home();
echo $my_ver;
Related Posts:
- Difference Between Filter and Action Hooks?
- How do you use the plugin boilerplate loader class to hook actions and filters?
- How do I Make a Theme “plugin-ready”?
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- Is it possible to create an action hook using do_action() within add_action()?
- Dynamically Override Fancy Title
- Define a function outside a class and call the function using action or filter hook
- Woocommerce – Hide a Column in Cart Table
- WordPress after content Hook & external template part
- Namespaced action and filter tags
- get_current_screen() return null
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- WordPress class, using add_action to call member function does not work
- How to get all queries’s results after they have executed?
- Hook add_attachment error
- How to find list of all functions bind to a particular hook from my plugin?
- Adding tables to dashboard pages programmatically?
- apply_filters() and call_user_func() to define and call a function outside a class
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- Apply function on all action hooks?
- Ninja Forms: Front-End Forms, Post ID?
- How to create an API for my plugin?
- Which hook should be used to add an action containing a redirect?
- Explanation of the “posts_join” and “posts_fields” filter hooks?
- add_filter OO with parameters
- How Do I Load My Action Earlier Enough?
- Does WP fire delete_post when trashed posts are automatically deleted?
- What’s the earliest point I can get the queried object ID?
- function triggered by “manage_users_custom_column” filter not working
- How to modify post content before writing to database?
- Actions or filters fired when data is saved in a custom table
- Determine which theme location a wp_get_nav_menu_items is for
- How can I hook into existing WordPress Bulk actions?
- Hook for post permalink update
- What is the Difference between directly call a function and call a function using add_action?
- How to add custom content under plugin row in WordPress admin plugin list?
- Does add_filter work outside functions.php
- What function to hook for changes made in status and visibility of a post
- Create a plugin to change the action to which a function is hooked
- Synchronize Custom post type tags to WordPress default posts tags
- Modifying values with add_action to be sent to db
- Hook to get image filename when it is uploaded
- Accepted arguments value in hook functions
- Which are the hooks run before/after when a category’s deletion?
- Should action callbacks start with a verb?
- Execute Hook on the footer or header after activating a plugin
- Which action hook to use for function?
- best practice for query string values – get_query_var always empty for my value supplied in query string
- Modify a function without editing template
- Adding option to Gallery shortcode
- correct way to call javascript into hook function
- Adding rewrite rule dynamically
- Get Time Taken By Each Action Hook in WordPress
- How to filter content for specific content variable
- WordPress custom taxonomy check box to dropdown
- I have 2 plugins using the same wp_login action hook and one is not working
- Valid filenames for add_action’s first parameter
- How dynamic action login_form_{action} is working
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- Override the WordPress core function wp_referer_field
- Bug: Post needs to be updated twice when adding action for save_post hook
- When does save_post hook fire on post save/update
- Remove an action by extending class and replacing it
- hook filter after the_content on a specific page
- Bind a function with its own argument to show something dynamically after every content
- WooCommerce change Tax Class programmatically when Recalculating an existing Order [closed]
- Update variable value via add_filter
- Configure WordPress to Generate Scheme-less Relative URLs
- Can I Hook Into the TinyMCE Insert/Edit Link Button to Use Shortlink For Post?
- Include HTML (Bootstrap Modal Box) with a plugin into my header
- Insert Content Before div#main from the functions.php File
- Using init hook for register_taxonomy is causing invalid_taxonomy in wp_insert_term()
- Setting post_id for single.php based on URL without a redirect
- Action / Hook when a new plugin is added
- Override category archive page title (not the head title)
- Limit get_next_post to posts from the same author
- The function called on the wp head hook becomes null
- Save_post – Warning: Cannot modify header information
- How Do I Unhook This Parent Theme Function?
- Any way, hook to add content right before the “read more” link?
- Use action, filter, or hook to append HTML to WordPress plugin function
- Does hooking into a plugin action / filter override the plugin’s function for that hook?
- wp_ajax add_action fuction won’t fire on custom jQuery action
- remove different admin menu for specific users
- WordPress Reset password Strength set to medium
- Add_action not calling callback function
- add_option_{$option} action hook not being called
- Function not working on any file other than the main plugin file
- Does WordPress have something like timer hook?
- Template file structure , wordpress hook for altering the template
- WordPress permalink setting
- How can I set a dynamic value for post_updated_messages based on return value of post_updated?
- How do I replace title with my plugin?
- add query string to all pages after user logged in
- Insert plugin html content to a specific spot in the frontpage
- get_term_by() returning null on plugin
- Is there a hook that I can use when a fatal error occurs?
- merging an array to an existing array using add_filter
- Override a function defined in wp-includes/comment-template.php