Solved

Trigger custom code when wordpress post inserted or updated

Posted on 2014-02-16
1
501 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Survey branching tutorial 11 49
WordPress Page Content Lost 2 23
Make an array show the subkey and put it in a query 2 29
geting data from the array list 6 18
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

696 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