Answer by @Pieter Goosen :
If you need to update the page before the main query fires and returns
the page object, you will manually need to parse the URL (probably on
init) and get the page ID from get_page_by_title() or
get_page_by_path().Otherwise, ‘wp’ would be earliest hook to get the page ID, for example:
function my_early_id() {
$post = get_post();
echo $post->ID;
}
add_action( 'wp', 'my_early_id' );
Related Posts:
- Hook that get’s triggered when the author of a post is changed
- The hook for the AJAX Add to Cart button?
- Get old values for post before saving new ones
- Execute function when post is published
- how to limit edit_form_after_title hook to page and post edit only?
- Action hook ‘wp’ firing twice… why?
- In what sequence are the hooks fired when a post is “published”?
- Better post meta efficiency?
- Count singular post views automatically
- How to change post status from publish to draft using hook in wordpress?
- Filter post before *editing*
- WordPress Delete hook with wp_delete_post function?
- Custom function for “Submit for Review” hook
- How to place HTML below the title of the (custom) post overview
- How can I hook into creating a new post and execute wp_die(), before the post is inserted into the database?
- Does an action fire when adding a tag via the “Tags” meta box?
- Are posts updated or built from revisions + autosaves?
- How can i do something after head like adding a hook for after head but before post
- Action hook for new pending posts?
- How to retrieve the postID in a “image_send_to_editor” hook function?
- Register post status, exclude from searches
- How to modify post content?
- Which WordPress hook fires after post content loaded?
- What is the filter or hook to add admin controls to posts on the front end?
- Adding buttons to Add New Post and Add New Page
- use wpml_post_language_details function other plugin based on $post->ID [closed]
- Hide a specific category in admin All Posts page (WordPress)
- How to access $post from a callback function
- Updating post data on save (save_post vs wp_insert_post_data)
- Copy post to separate database with “add_action(….)”
- Hooking into the post editing screen for an existing page only
- Trying to alter the post_content through the_post
- Call Web Services on post first publish
- How to dynamically parse and transform post/page content before displaying it?
- What does WordPress do if I save a post without content/title? [duplicate]
- Adding bootstrap classes to video shortcodes
- preg_replace not removed “class”
- why the same code got different results when using query_posts in functions.php and index.php
- Divs appearing everywhere in post content
- Modify posts listing at back end
- Hook for changing excerpt content when excerpt not set
- Is it possible to add a shortcode below post title?
- Automatically set post_parent value
- Posting to WP via URL
- Is there a way to know when a page has been updated and do some action only once?
- Restricting displayed posts to posts from only select authors
- How can I change the date format of the revision list?
- Hook when post is set from published to draft?
- Is update_post_meta used when save_post action hook is invoked?
- Get Category in save_post Hook
- Count singular post views automatically
- How to prevent post update using transition_post_status
- Grab meta data before post is saved
- Can’t get post_updated hook to work
- How to get the postID inside ‘content_save_pre’? Other hook?
- wp query custom orderby not custom field
- How to remove related post from home page
- Checking if some condition is matched before inserting post into database
- fire action when post is being edited as well as saved?
- Which hooks are essential for post templates?
- save_post not working
- Admin notice on wp_insert_post
- Should we trust the post globals?
- Add a checkbox to post screen that adds a class to the title
- How to have different content in the loop and single
- Make “Post published. View post” Open in a New Tab
- Custom Post Type & Author not associating, user post count is 0, api doesn’t return author in post objects
- How to update serialized post meta?
- Can wordpress differentiate between added and updated posts?
- Accessing post->ID outside of the loop for listing child pages
- Adding parent pages to posts
- Limit posts per author role (excluding admin) in home page
- I want to display custom text widgets for each post in the sidebar?
- Search by post title and content in wp_query without order
- Remove a shortcode from all WordPress posts
- post category in wp_insert_post
- Show comment number per author per day
- How to remove specific tag from multiple posts?
- Why this function doesn’t works without the_post?
- l accidentally permanently deleted a Draft. There’s any way I can recover it?
- Lightbox on wordpress post page
- WordPress Architecture as a CMS – Posts & Pages
- Getting post and attached image from subdomain
- How to list post as buch of category, and all of them
- Not adding a new post?
- Prevent the automatic URL linking added in last update
- Thumbnails and images in the blog post are not loading
- Automatically delete post in a single category when a new one is created
- Multiple posts in one page
- post__in no longer works in wordpress 5.0.3
- How to allow some visitors to edit inline specific post
- How to display most popular posts from certain category in sidebar?
- Is possible to do this from function.php
- Make Show Notes for Individual Podcast Episodes Easy to Find (multiple URL’s?)
- Users cannot post when editor or admin on more than 1 site on multisite
- Creating / Editing a post from within site template
- display only the title of the post into a certain category
- WordPress “Posts Page” isn’t showing template dropdown
- How can I get on the same row two post of different categories?
- WordPress + Polylang – Error 404 when trying to preview draft post on different language