As @Even commented, instead of url_to_postid()
, you should be using something like this:
if ( ! is_single() ) {
return;
}
$post = get_post();
url_to_postid()
is a round-about way of getting the ID of the current post, when WordPress has already determined what the current post is, i.e., it has already parsed the URL to get the post ID.
Related Posts:
- How do I ensure I can loop through every enqueued script and CSS?
- How to add a javascript snippet to the footer that requires jQuery
- How do I create a custom role capability?
- How to enqueue JavaScripts in a plugin
- How to include jQuery and JavaScript files correctly?
- Prevent network activation of plugin
- Uninstall script for a plugin in Multisite
- Changing Plugin Load Order
- Load js/css files only on specific admin UI pages
- What is wrong with using add_option with Multisite instead of add_blog_option in a plugin
- Get list of scripts / styles and show file which enqueued them
- How to Get a List of Sub Blogs without Using get_blog_list()?
- jQuery in header or footer
- Enqueue script only when shortcode is used, with WP Plugin Boilerplate
- How do I conditionally enqueue script for CPT single post type with plugin?
- Cron firing my function everytime wp-admin is visited
- Error getting correct blog_id on MU from functions.php
- How do I make specific plugin functionality apply to different sites in a network?
- WordPress multisite apply different options over each site from same plugin
- Filters ‘request’ and ‘parse_query’ not firing in sites.php nor link-manager.php
- Only allow plugin to be activated on root site of multisite
- How to use wp_set_password in a plugin?
- WordPress Media mime type filter problem 4.0
- Script won’t load via plugin class
- Plugin Loading Scripts and Styles on Every Page – Even when not being used
- What is the best way to overwrite /wp-admin/ms-delete-site.php
- Inserting JS snippet in the footer if there is no wp_footer?
- Can’t get JS code to work with shortcode
- Where should I store global data for my multi-site WordPress plugin?
- How do I add a javascript file to all admin pages via a plugin?
- unable to stop loop when using wp_insert_post with publish_post hook
- Customize multisite site creation with user data
- how to activate plugin network-wide, and save setting across sites
- Sharing a common set of image files for media library, across all sites within multisite
- What is difference between blog id and site id?
- How to create a Tools menu on the Network Admin dashboard from a plugin
- How to run a external JavaScript file on wp-admin if admin, and other if normal user?
- How to set “Site Address (URL)” programmatically on WP multisite?
- Loading scripts with wp_register_script and wp_enqueue_script
- Where to call wp_enqueue_script in a plugin with custom template?
- How to associate an existing user to a site in a multisite setup programmatically
- Replacing Scripts in Admin Load_Scripts
- Is there a way to ensure plugin script loads before another script?
- How To Change Post Author Default?
- conditionally load javascript & CSS for do_action() calls from plugin
- What stylesheets are available in core?
- Plugin menu addition in multisite
- What should happen when a WordPress Plugin is activated across the network (Network Wide Activation)
- Multiple Plugin best practice in Multisite
- How to enqueue or include json file to a plugin
- How to load library scripts in admin from plugins in noConflict wrapper?
- jQuery does not enqueue for my purpose… (before an inline script in the footer)
- Problem with context in multisite – getting main site data in every blog (get_pages())
- Enqueue script globally
- how to invoke wordpress API from other existing PHP system
- WP Multisite login not working on one subsite. Possibly cookies/ history issue?
- register_activation_hook on multisite
- WP Plugin Running before jQuery
- wp_localize_script is not adding a global variable for javascript
- Loading Modernizr (or other JavaScript libraries) for use in a plugin
- How to import the css in the plugin admin area?
- My stylesheets are not enqueuing
- Plugin Development – Class Constructor Not Firing wp_enqueue_style action hook
- Custom Plugin – CSS works, JS doesn’t
- Enqueuing scripts and styles in custom plugins
- How to enqueue scripts in right way in a plugin?
- unable to wp_enqueue_script(‘suggest’);
- WordPress multisite,use same cookies across all website?
- WP: Search and replace in DB programmatically
- Using function from enqueued .js file in theme in plugin?
- Enqueue a file that’s not js or css
- How to get current logged-in user details in multisite?
- add_action wp_ajax_ not loading in plugin file WP Network
- Clean way to initialize plugin in newly-added site when plugin has been network activated?
- How to share user data across multiple WordPress websites?
- Enqueue scripts inside a class in a plugin
- Is there anything special required to make a plugin work in a multisite environment?
- Enqueue ONLY Plugin Styles and Scripts
- How to edit wp-signup.php content using plugin
- wp_enqueue_scripts in a plugin’s class
- WordPress Plugin Authoring question about jquery and css
- Loading Images from Javascript on the Front End
- Add default value from selection
- Is “document loaded” different on admin side than public side?
- plugin css is not being applied to the page
- Adding External Gmap JS to WordPress
- Append php file to footer
- How to avoid conflict if a plugin already have included open library?
- AJAX call of function containing javascript which is not loaded (Plugin development)
- Custom Plugin activation error in Multisite
- Replace “content-area” of themes 404 page with plugin?
- Javascript not being loaded only in custom taxonomy template
- Ajax Response Error | just getting error as the response
- Add a Script button in W3 Total Cache plugin not working due to conflicting jQuery version
- Enqueue scripts based on site.
- Same header/footer in Admin, across all network sites in multisite
- Enqueue script not working
- Change Admin menu placement using hooks
- Enqueue Script in custom plugin before other
- How to only Load scripts on variable products page