Solved

Trigger custom code when wordpress post inserted or updated

Posted on 2014-02-16
1
505 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

687 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