Solved

Trigger custom code when wordpress post inserted or updated

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

831 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