Solved

Trigger custom code when wordpress post inserted or updated

Posted on 2014-02-16
1
494 Views
Last Modified: 2014-03-01
Hello

If i wanted to modify a wordpress theme such that some of my custom code was ran when a post is inserted or updated (either before or after the insert - probably -after actually) please could you advise how i woudl go about doing this. Even a simple example which just echoed hello world to screen after an insert/update would be much appreciated

Thanks
0
Comment
Question by:andieje
1 Comment
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 39862716
I'm not a Wordpress expert, but there is the "save_post" hook. Something like this in your theme functions.php file perhaps:
function my_custom_after_post_code( $post_id ) {

	echo "Hello";
}
add_action( 'save_post', 'my_custom_after_post_code' );

Open in new window

http://codex.wordpress.org/Plugin_API/Action_Reference/save_post
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
This article discusses four methods for overlaying images in a container on a web page
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now