Try something like
$post_id = url_to_postid($_SERVER['REQUEST_URI']);
Might need some tweaking: might need 'HTTP_REFERER'
instead of 'REQUEST_URI'
; might need to append the protocol and the domain to the string passed to url_to_postid()
.
Related Posts:
- send popup after wp_redirect()
- How do I get a function to work in single.php
- Displaying Logged-In User Name in WordPress Menu
- How to call a function only once (global variable scope)
- Multiple is_page() in page.php
- Set media upload attachment link to none and hide it in WP v3.5
- Fatal error: Call to undefined function plugin_dir_path()
- Switching wp_get_sites to get_sites
- Is it possible to get a theme customizer setting from wp.customize using jquery?
- One button to change all settings in theme customizer?
- Add custom image sizes to media uploader
- How can update custom meta for all posts
- How to add default images into theme customizer image control?
- Is $hook a global variable in WordPress
- Successful or Error Message after running mysql code in functions.php
- How can one utilize a variable as a callback function name for add_settings_field
- Custom Logo URL | Help me print the URL of the custom logo I inserted into my theme
- wrong php date()?
- Include a php file from functions.php only to homepage
- How do I fetch all comments per post via WP REST API?
- Shortcode content output but not in correct place
- How to restrict page access to logged-in users?
- Handling Body class based on Template
- Adding Default Settings to Theme My Login plugin
- Automatically adding new post categories to menu
- Get post id in a function when edit/add a post
- function to assign user role based on a field from usermeta
- get author_name from queried post
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- WordPress Gravatar filter is removing my custom attributes
- Pass php dynamic variable to shortcode
- Incorrect amount of posts returned when filtering related Woo products by custom taxonomy
- Query Pages and post excerpts dynamically
- Get my site session in wordpress?
- How to list posts from a plugin taxonomy?
- Register a menu – Error Header
- Filtering a function’ output for a new continued function
- Shortcode to find and replace URL
- Deleting Certain terms from appearing on the front end as links
- first instantiated SimplePie object cosumes 5mb?
- Theme not calling Jquery properly
- Function Reference Documenting Template Tags for use in Custom Theme Templates?
- WordPress redirect redirecting too many times or not at all
- Set site title & tagline with wp.config or function.php
- Shortcode to embed Edit Account form not working
- How to make jquery count down timer function manually editable
- Hierarchical taxonomy list with modificated term links
- Add value to new attribute inside WordPress menu items
- Please show me how to use an if/else statement in combination with wp_enqueue
- If Array Values Match Another Array’s Values, Then
- Get user custom field value on function.php
- entire JS folder not loading in a WP theme
- Open and closed function [closed]
- Need to Modify a WordPress Shortcode with another wordpress shortcode
- Else/If Statement to Display Photo Descriptions
- Count foreach and display in menu php
- Dynamically Generate Functions and Hooks
- Strip from or something better?
- Display additional page templates and a sidebar on plugin activation
- Remove role of user after X days
- User filter posts by year
- bp-custom.php is not working on a WordPress multisite environment. how to fix it?
- Need help for some PHP code
- Add a Metabox checkbox to the Page Edit screen of wp-admin , which only certain roles can see and Makes only certain roles able to Edit said page
- Adding HTML Code to Replace Text in PHP
- how to replace h1 entry title with h2 in category pages only
- How to unset a function from a action inside a class, that is called in another class
- Create a new account on site B with data from the purchase of site A
- Why is the current page loaded in the pop-up window and not the specified one?
- if get_post_meta is empty echo a placeholder or shortcode
- Limit Search to Product Pages only unless I’m on Blogpage or Blogposts
- WP query posts BUT show the most recent and one per author
- PHP multiple forms, same page, isset($_POST[]) not working?
- Outputting post content to jQuery .html() string
- shortcodes, custom php and their errors
- PHP “warning include_once(): Failed to open stream” Simple HTML DOM in WordPress Child Theme
- In a foreach loop, how can I add a meta value if it doesn’t exist?
- Woocommerce – if selected attribute term equals
- split 1 cart item into instock and back ordered
- post_exists stops working in a scheduled event
- How to call WordPress PHP file using external js file
- Using get_theme_mod with checkbox to display content
- use system script advertising in wordpress multisite
- Use WP_Query Data In Cookie
- Extend the WP_Customize_Image_Control class to change its non-frame $button_labels
- Styling admin page rows in order of importance (checkboxes)
- Insert wordpress tags below posts via functions.php
- Help with my first Metabox helper class
- Pagenav Not appearing on custom Template
- ISOTOPE – Missing/Invalid Arguement Get Terms
- Pagination not displaying
- My title is showing after the shortcode
- Load a Header in wordpress
- Trouble figuring out how to get my button to submit comment
- Setting WooCommerce currency programmatically
- Masking external links with internal link for member-only
- Adding multiple conditional tags in a function?
- a problem in class in class-wp-hook.php
- change title of page dynamically
- Custom plugin doesn’t show in admin menu – when code added, displays an empty page