0

World!

Why not fire the save_post event?

function action_function_name_13( $content ) {

  $content = '<div>' . $content . '</div>';

  return $content;

}

add_action( 'save_post', 'action_function_name_13' );

You need to perform actions with the $content variable, that is during the save or update a post.

Sorry, translated by the interpreter...

1

The save_post action hook fires after a post is saved: every time, even for autosaves.

If you look at the reference for save_post, you'll see that the callback receives three parameters: the first is an integer $post_ID, the second is a WP_Post object $post, and the third is a boolean $update. None of the parameters are a string of the content.

Based upon your code, it appears that you are trying to add a filter to the_content. So your code should be:

function action_function_name_13( $content ) {
  return '<div>' . $content . '</div>';
}
add_filter( 'the_content', 'action_function_name_13' );

If this isn't what you're trying to do, look through the hook reference for a hook that describes what you're trying and update your question.


Here's a way to modify the post content after it has been saved to the database.

//* save_post fires *after* the post has been saved to the database
add_action( 'save_post', 'wpse_266719_save_post', 10, 3 );
function wpse_266719_save_post( $post_ID, $post, $update ) {
  //* Remove action so it doesn't fire on wp_update_post()
  remove_action( 'save_post', 'wpse_266719_save_post', 10 ); 
  $id = $post->ID;
  $content = htmlspecialchars( $post->post_content, ENT_QUOTES, 'UTF-8', false );
  $postarr = array( 'ID' => $id, 'post_content' => $content, );
  wp_update_post( $postarr );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.