Title: Hook for modifying post content
Last modified: May 9, 2018

---

# Hook for modifying post content

 *  Resolved [swinggraphics](https://wordpress.org/support/users/swinggraphics/)
 * (@swinggraphics)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/hook-for-modifying-post-content/)
 * I want to broadcast a page that contains internal links and automatically rewrite
   those links replacing the parent site_url with the child site_url. What hook 
   should I use, and what part of the API is relevant?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [edward_plainview](https://wordpress.org/support/users/edward_plainview/)
 * (@edward_plainview)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/hook-for-modifying-post-content/#post-10264313)
 * My favorite actions are:
    - threewp_broadcast_broadcasting_started
    - threewp_broadcast_broadcasting_modify_post
    - threewp_broadcast_broadcasting_before_restore_current_blog
 * The first action I use to note down whatever links I find in the post_content
   that are relevant to the parent blog.
 * The second action is to modify the post content with new data.
 * The third is to modify other things, like the custom fields.
 * The post in question you’ll find in the first parameter: $action.
    $action->broadcast_data-
   >post or $action->broadcast_data->new_post
 * You should look at broadcast / src / traits / broadcasting.php, which contains
   a lot of nice code, I hope. 🙂
 *  Thread Starter [swinggraphics](https://wordpress.org/support/users/swinggraphics/)
 * (@swinggraphics)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/hook-for-modifying-post-content/#post-10264319)
 * Thanks for the super fast reply! :O
 * I’ll have a look and post my solution when I work it out.
 *  Thread Starter [swinggraphics](https://wordpress.org/support/users/swinggraphics/)
 * (@swinggraphics)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/hook-for-modifying-post-content/#post-10278950)
 * Example for others interested:
 *     ```
       add_action( 'threewp_broadcast_broadcasting_modify_post', 'my_broadcasting_modify_post', 20 );
       function my_broadcasting_modify_post( $action ) {
       	$bcd = $action->broadcasting_data;
       	$parent_site_url = get_site_url( $bcd->parent_blog_id );
       	$child_site_url = get_site_url( $bcd->current_child_blog_id );
       	$modified_content = $bcd->modified_post->post_content;
       	$modified_content = str_replace( $parent_site_url, $child_site_url, $modified_content );
       	$bcd->modified_post->post_content = $modified_content;
       }
       ```
   
 * I’m trying to make this into an option with a checkbox in the Broadcast metabox,
   but I haven’t figured out yet how to get the options to stick.
 *  Thread Starter [swinggraphics](https://wordpress.org/support/users/swinggraphics/)
 * (@swinggraphics)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/hook-for-modifying-post-content/#post-10280200)
 * Full code, including checkbox added to Broadcast options:
    [https://gist.github.com/swinggraphics/78057a3af32eec21c8bf47c734638528](https://gist.github.com/swinggraphics/78057a3af32eec21c8bf47c734638528)

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Hook for modifying post content’ is closed to new replies.

 * ![](https://ps.w.org/threewp-broadcast/assets/icon.svg?rev=1013783)
 * [Broadcast](https://wordpress.org/plugins/threewp-broadcast/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/threewp-broadcast/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/threewp-broadcast/)
 * [Active Topics](https://wordpress.org/support/plugin/threewp-broadcast/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/threewp-broadcast/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/threewp-broadcast/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [swinggraphics](https://wordpress.org/support/users/swinggraphics/)
 * Last activity: [8 years, 1 month ago](https://wordpress.org/support/topic/hook-for-modifying-post-content/#post-10280200)
 * Status: resolved