Solved

Trigger custom code when wordpress post inserted or updated

Posted on 2014-02-16
1
492 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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
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 …

762 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

8 Experts available now in Live!

Get 1:1 Help Now