Trigger a Link once a new post is Published

139 views Asked by At

Is there Anyway to trigger a link once new post is Publish ?. My goal is to use it to ping sitemap

http://google.com/ping?sitemap=http://www.example.com/my_sitemap.xml

I simply don't want to set cron job for this. Please Gurus in the house is there anyway I can use theme function to achieve this ? I am new to wp coding Please.

2

There are 2 answers

1
Richard On

From the Wordpress Plugin API:

publish_post is an action triggered whenever a post is updated and its new status is "publish"

So in your theme's functions.php, write your function to call the google url, then use the add_action function, with publish_post as the hook, and your function's name as the callback.

1
utsav tilava On
function test()
{
  write code here.....
}
add_action( 'publish_post', 'test' );