A simple solution for you – this hook will send you a full URL to the post that is being published. Don’t forget to update [email protected]
function post_published_notification( $ID, $post ) {
$permalink = get_permalink( $ID ); // GETTING THE PERMALINK
$to[] = '[email protected]'; // UPDATE THIS
$title = $post->post_title;
$subject = sprintf( 'Published: %s', $title );
$message = sprintf( 'View: %s', $permalink );
wp_mail( $to, $subject, $message, [] );
}
add_action( 'publish_post', 'post_published_notification', 10, 2 );
If you want it to work on post update as well, just add this action to the bottom of it:
add_action( 'save_post', 'post_published_notification', 10, 2 );
You can add this hooks to the bottom of your functions.php or in your plugin.
Related Posts:
- transition_post_status hook, works – but not if the post is new
- Disable Attachment Pages Completely
- Multiple is_page() in page.php
- Change the footer text on the login page
- How to remove a metabox from menu editor page?
- Check if page parent has certain template
- class=”parent” for wp_list_pages?
- add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
- Listing all sub-pages?
- Hooking new functions to actions + passing parameters
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- Is $hook a global variable in WordPress
- $post object is null
- New Plugin Review
- Print number of post (in reverse)
- Use template for posts with a particular category grandparent
- Insert all post IDs in new database table
- syntax issue on php 7.4
- How do I publish only one page to production after making changes on staging?
- Can’t load WP function into external function
- Randomise upload filenames (or another solution to hide the original image URL from theft?)
- Query all posts of a custom taxonomy term
- Handling Body class based on Template
- Can’t get page content in WordPress
- Way to querry data (tags) from a wordpress database?
- Best practice for migration friendly images in posts/pages?
- Get post id in a function when edit/add a post
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Why ajax doesn’t work on certain wordpress hooks?
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- WordPress Gravatar filter is removing my custom attributes
- Function works everywhere, how to keep it to execute when creating a new post
- Parsing Menu Items and Blog Posts
- Pagination on Custom Post
- How to use theme function in post/page?
- Theme not calling Jquery properly
- Automatically add images to a menu
- How to catch wordpress post ID when it’s published
- WordPress redirect redirecting too many times or not at all
- Why does the post_type_link hook everything twice?
- Need php code’s output to display underneath a Divi Module
- How to have different site identity logos on each page on Astra Theme [closed]
- How can I hook into the wp_mail function used by BackWPup?
- Get user custom field value on function.php
- How to use mysql LIKE with wpdb?
- Reading settings in the home page precisely home.php
- get post id from wp_insert_post for get_template_part
- Adding function to child theme’s function.php
- PHP Output also in Child theme, but different
- Must filter functions receive all arguments passed to them?
- How to Display a List of Child Pages For a Parent Page in WordPress
- Creating customized php files in theme folder
- WordPress Search
- Dynamically Generate Functions and Hooks
- How to pass hook variable to function?
- remove specificly the last tag in all posts
- Edit and delete permissions pages and posts
- My worpress search page is showing no results
- A function to get the content of a page
- Filter wordpress posts without searching the keywords in the post content
- How do I add a function to parent theme
- How to Send Pingbacks for all Posts in WordPress?
- Contain multiple page templates in one PHP custom template file in WordPress?
- How can I check if a post with a particular slug or title exists?
- Wp_Schedule_Event every few minutes doesn’t work
- Adding custom field to product category and show it to shop/category shop page
- posts_per_page displays only 2 posts instead of 4 posts
- Split post or page content in two or more columns
- Custom meta box is not displaying value showing tag as empty
- Discount in the specific product title using keyword ( Woocoommerce )
- Send POST request to Flask app from functions.php file
- How do I get the value of a current user’s custom field?
- How to center all text body in single.php at once?
- Hook into all password resets in WordPress and get password before hashing?
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- Displaying POST content with HTML tags and all
- Get current_post in reverse order with pagination
- Why transition_post_type hook is called twice for the same post?
- Using Tag Groups: Displaying groups and adjacent tags of current post
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- insert thumbnail image from php script
- Can’t put a hyperlink on Featured Post’s Image
- Weird Behaviour: Not all WordPress Posts appearing
- Published custom posts missing
- WordPress get_post_meta issue
- WordPress HTML Helper
- List of child pages fetch next results at link click
- Insert wordpress tags below posts via functions.php
- Trying to see if page is category or single and displaying title with appropriate heading tag
- How to modify this function to exclude also the post belonging to a specific category?
- How to display the date under the post title?
- How to return a Boolean for a page that is a subpage thru its name?
- Assign new post author IF another user in custom field on post transition
- Create and publish a new post every Monday, listing the post titles and links to the posts published during the previous week
- Add multiple HTML attributes to an Elementor button
- WooCommerce: write featured image dimensions to custom fields in product’
- How do I get a function to work in single.php
- Is there a hook that I can use when a fatal error occurs?
- How to change post date and post time in WordPress automatically with a function