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?
- ajaxurl not defined on front end
- 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
- Where to enqueue stylesheets for plugin?
- 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
- Multisite, sharing content by URL
- When is it too late to call the action wp_enqueue_scripts?
- Only allow plugin to be activated on root site of multisite
- Use js script from one plugin in another plugin
- 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 you output enqueued scripts to an admin page?
- 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
- Plugin Uninstall and Deactivate via Options Menu
- 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?
- is_page() function doesnt working
- How to create a Tools menu on the Network Admin dashboard from a plugin
- How to avoid loading same script twice?
- How to run a external JavaScript file on wp-admin if admin, and other if normal user?
- Override the default Add/Edit site forms of the Network Panel in custom plugin
- How to set “Site Address (URL)” programmatically on WP multisite?
- Enqueue scripts in footer
- Loading scripts with wp_register_script and wp_enqueue_script
- Adding Dropbox dropin js using wp_enqueue_script
- Where to call wp_enqueue_script in a plugin with custom template?
- 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
- How to make my shortcode load scripts and styles, from within the plugin?
- How do I get rid of my inclusion race-condition on wp_enqueue_script
- Using function from enqueued .js file in theme in plugin?
- Enqueue a file that’s not js or css
- Enqueueing common php scripts in a plugin
- 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
- Multisite and the JSON REST API: How to?
- Enqueue scripts based on site.
- Testing Plugins for Multisite
- How to enqueue an external Javascript file to Frontpage footer
- Same header/footer in Admin, across all network sites in multisite
- Enqueue script not working
- Script work on non logged in user but not work for logged in user?
- Change Admin menu placement using hooks
- Why does this fail: Disabling plugins enqueue_script() in functions.php
- Enqueue Script in custom plugin before other
- How to only Load scripts on variable products page
- Force remove parent theme CSS/JS and call them from Child theme
- wp_enqueue_script() with unknown path and maybe symlink
- 2 Domains pointing to SIngle WordPress , issues with links
- the second js file enqueued inside wp plugin isn’t read
- Gutenberg Static blocks: viewScript doesn’t import css for frontend?