Pull the add_action()
outside of the function, and put the conditional inside the callback. Also, if you’re printing a script directly, use wp_print_scripts
instead of wp_head
. You also have a syntax error.
function testingone(){
if( get_option( 'MyOptionName' ) ) {
?>
<script>var Script = GoesHere; </script>
<?php
}
}
add_action( 'wp_print_scripts','testingone' );
Related Posts:
- How to add inline css/js inside a shortcode
- Inject HTML meta tag inside wordpress tag using add_shortcode
- Where is the best place to use add_filter
- When can you get current page ID and initialize hooks right after?
- How to find out if option exists but is empty?
- Using the ‘draft_to_publish’ hook (post status transition)
- How to load different css file for different pages
- Enqueue style inside shortcode but its loaded at the bottom of page (before footer scripts)
- Custom plugin settings: clicking “save changes” does not display success message
- How can I limit functionality in one version of a plugin?
- Shortcode display outside the div
- How to fetch serialized data from wordpress options
- Good tools for locating hooks in a wordpress page/admin interface/blog post?
- Can a plugin add to header/footer/body content?
- Is it possible to add an action to the currently running action?
- Get all options saved by another plugin
- Action on post publish
- How to call bind function in wordpress actions or hooks
- How to prevent action in ajax request, when in admin side?
- template_redirect not being called when using ajax
- Why is the Settings API is not saving my array of options
- What are the benefit in adding hook in the init() hook?
- add_action in functions.php, do_action in plugin?
- Default Plugin Settings Not Writing to Database
- add action for displaying posts using a shortcode
- ‘wp_login’ action hook not working with wp-login.php file
- Update Option Error: Notice: Undefined index
- Serialize data for wp options
- How can I add an options page for my class based plugin?
- Any hook for pre-plugin-update -either bulk or single plugin update
- Get plugin option in another PHP file
- Create mobile navigation header with settings integration
- wordpress plugin is not activating from widget
- When to load auto-login code?
- How to get all of the activate_plugin action parameters?
- How to get specific setting by settings_fields()?
- How to check current user before all actions and filters?
- Add Plugin options as subpage to Theme options page
- Get Time Taken By Each Action Hook in WordPress
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- php page not found for plugin options menu
- Custom plugin init action causing general slowness
- add tabs in rdp-plugin/includes/settings.php and get settings saved
- wp_footer hook only working on homepage not in other pages
- Redirect to another page using contact form 7? [closed]
- Add action to fire when a published post is updated
- How to pass variables to a function argument using add_action [duplicate]
- WordPress error: Options page Setting_ not found in the allowed options list
- Submit Form data to another page via Ajax (WordPress Way)
- Can I use register_settings and unregister_setting once the settings page has loaded?
- Does using `add_action( ‘init’…` cause performance issues?
- update_option_{$option} not showing old value
- How to prevent plugins from sniffing/stealing other plugins’ options?
- Hook for page Request?
- get_option / wp_localize_script Not Working in OOP Plug In
- wp_enqueue_style on template_redirect level?
- Custom CSS not being added by plugin
- How to use add_action for multiple instances of the same class
- How to append new form elements in “Add New” form of Users in WordPress admin panel?
- Need to add/remove group of options and display them as rows
- How to get values from network settings panel?
- I cannot include a file in my plugin settings page
- How to make sure settings are not lost when plugin is updated?
- wp_options not returning value for logged out users?
- How to save Setting pages data to the database?
- Problem with MEMCACHE and Redis with wp_options
- Why do actions with class and public method don’t fire __construct()
- The function called on the wp head hook becomes null
- i create functions.php in plugin files but add_action (‘wp_head’, ‘function_name’) don’t work
- Nested Actions and Filters
- Passing function into add_action always returns the first argument
- Get post content inside plugin class method
- Remove action added in plugin class from theme
- Plugin Options Page and Subpage
- How to save the option’s new values plus old value without overwrite old one
- WP options plugin setting not saving the selected checkboxes
- Echo custom admin field into a is_single()
- Protect WordPress option value
- WordPress Boilerplate Plugin doesn’t see callback functions for add_settings_field and add_settings_section
- How do I add a textarea (multirow) option to my WordPress plugin?
- echo plugin results on pages
- Front End Page Not Loading Header Footer
- Why is the WordPress update_option not working in this code?
- How to create a new database table whenever user changes options
- Create Array from data in the OPTIONS table
- Plugin Hook: Get posts
- Validating values using Settings API?
- Saving an array to get_options
- Is it possible to cancel a post status transition?
- Building a simple “settings” plugin to change textstrings on the home page
- My first plugin doesn’t save the data in options
- How wordpress plugin hooks works? [duplicate]
- How to access values from your own settings page in javascript?
- move setting data from wordpress api to codestar freamwork
- add_action() not working for admin
- When to store store plugin options as a single database record?
- wp_head filter not executed inside custom class
- Pluging with content for a specific page or post
- How to automatically activate users after registration without activation email?
- Creating a plugin that will display text on every page