when you are at the post URL, you don’t need to work with referer (which is not reliable moreover) but with $GLOBALS["post"] because you are in the PHP code which generate the page
then you can have the post ID with that :
$post_id = $GLOBALS["post"]->ID;
Related Posts:
- Adding tawk.to code just before body tag on functions.php file
- Deregistering a script in WordPress seems impossible
- How to inject variables into public-facing JS using wp_enqueue_script
- WordPress Scripts Being Loaded in Footer
- Is the wp_enqueue method efficient?
- How to use wordpress function wp_enqueue_script() in php?
- ‘Bones’ theme: Load stock scripts in footer instead of header?
- Using Google Analytics in an enqueued JS file
- Most efficient way to add javascript file to specific post and/or pages?
- Pass media upload value to input field
- Trigger a php file on every post or page if a condition is met
- Where exactly do I write define( ‘WP_DEBUG’, true ) in wp-config file
- Data fetch and delete by ajax request
- Execute only on a certain page
- JavaScript, best way to use data from the loop
- How can I add tinymce editor in WordPress with jQuery?
- How to enqueue CSS and JS only on specific template?
- Slide in Panel WordPress Post
- Using shipped version of jquery
- Bridging TinyMCE js and WordPress PHP?
- Trying to implement Ajax comments in WordPress, getting WP error
- class click counter save number
- WP functions in .js
- Ajax – Call to undefined function get_option()
- Populate dropdown with Child Pages based on Parent Page chosen
- How to prevent XSS alter custom global javascript object & methods in WordPress
- JS file work only in index page
- Javascript file is not working on single.php wordpress [closed]
- How to change redirection route to a php page for making it only accessible by logged-in members?
- Integrating PHP into Javascript to display map markers with Google API – problem with wp_localize
- How to send Ajax request from my plugin in admin dashboard?
- Customizer: Multiple CSS styles on same element in Live Preview
- How to register javascript variables in wp_localize_script?
- How to pass Select value from Javascript to PHP to generate select option on change
- How does wp_enqueue_scripts work?
- AJAX success response is not working but it’s saving my changes
- How do I Import / Upload Files with jQuery AJAX?
- Noscript not working as it should in wordpress site
- PHP echo inside javascript
- Correct way to enqueue page specific CSS file
- How to add API security keys into JS of wordpress securely
- Add Codepen animation as Preloader to WordPress
- HTML escaping data with ajax requests
- 2nd page displaying the exact same posts as my first page (minus the very first post)
- How to: Conditionally Enqueue JS and Stylesheets, for Custom Post Type (Single and Archive Templates)
- Get related product based on subcategory selected from category id with ID 142
- wp_nav_menu not working correctly in my underscores theme
- Enqueueing a code block from an options framework
- Is it possible to isolate and use WordPress functions outside of wordpress
- Load Javascript for a widget WordPress
- Testing a Form’s Zipcode Field with Regular Expressions to Determine WordPress Page Behaviour
- security concerns if using html data-* attribute for l10n?
- Ajax on the Administration Side of plugin – wp_localize_script – how to pass value from JQuery to PHP function in class?
- duplicate posts with ajax load more wordpress
- How to populate a Gutenberg select field SelectControl with option value from PHP array
- Send an e-mail on address with the link with disliked post
- How to extend SelectControl with data from my theme
- Search bar for wp menu
- Show next image in array if page is revisited by same logged user
- Executing php on button press
- Fetch Data from an external MSSQL Database in a Managed WP hosting
- How do I disable cache for a certain page?
- How To Get HTML Eelement From Another Page
- Conditional Banners
- Update $wpdb query with AJAX
- $.ajax results in 403 forbidden
- Using Javascript On Page – Header and Footer Now Missing
- AJAX to add to cart multiple products woocommerce
- Filter portforlio with librairie isotop
- Cannot successfully execute AJAX script to call function.php specific function. Using XAMPP localhost to test
- sessionStorage saves input value in browser but it is not loaded in the form field
- Replacing entire tag with shortcode – JavaScript [duplicate]
- How can i get the same ajax result using WP REST API instead of admin-ajax?
- admin-ajax.php 400 bad request – whats wrong with my code?
- WordPress load javascript file if something… (after the page is loaded)
- Serve cookie free URLs in WordPress without using a CDN
- How to stop loading my custom scripts files for wordpress iframe?
- Force ‘permanent’ post cache of shortcode results
- Why I’m Not Having Access to “$_POST” Data Outside My AJAX Callback?
- 500 (Internal Server Error) of external php file
- Add title and caption to thumbnail image on mouseover
- Problems with plugin that fetches data from database with ajax
- Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)
- Require Credits Footer
- Adding jquery using php function
- How to hide .js files on wordpress website using php or wp plugins or any? [closed]
- notify users when changed database
- Import js variables loaded via wp_localize_script() into js module without global scope connection
- Having trouble customizing toolbar on wp_editor
- Load wp_editor on button click
- WooCommerce Modal Fly cart on add to cart – With AJAX
- Weird Javascript:void(0) code in my website
- get_post_meta returns on side but it doesn’t return on bottom of admin page
- Calling a function via a shortcode in javascript
- Manipulating the allowed inner blocks of a core-gutenberg-block?
- how to escape alert/window.location.replace with variable
- Registered a REST Route but I’m Getting a 400 Bad Request
- Add custom data attribute to every core Gutenberg Blocks
- How to get the content of a dynamic block in PHP
- How to inject right sidebar on post edit page?