1. // Make sure Activitypub services embed videos
  2. // plugin will skip embedding videos if it detects a feat. image
  3. // @param obj $ap_obj An object array of the post for Activitypub to use
  4. add_filter('activitypub_activity_object_array', function($ap_obj){
  5. // The "id" key is actually the URL/permalink of the post, not the post ID.
  6. // Get post ID from the permalink
  7. $post_id = url_to_postid($ap_obj['id']);
  8. // Check if a #video micropost
  9. if (has_tag('video', $post_id) && has_category('microblog', $post_id)) {
  10. // Remove any media attachments
  11. $ap_obj['attachment'] = [];
  12. }
  13. return $ap_obj;
  14. }, 100);

This code assumes you categorize and tag your posts the same way I do (“Microblog” for as the category, and “video” for tag). You might want to change it to fit your own system.

Change this line: if (has_tag('video', $post_id) && has_category('microblog', $post_id)) {

The Activitypub Object Array?

The filter activitypub_activity_object_array is used to modify the object array of the post. This is completely different from WP_Post. You can see the object array of each post by appending /activitypub to a post. Ex. (source)


I have a lot of “video” type posts, where the main content is a single video. If the post contains a “post thumbnail”, the Activitypub plugin automatically considers it media (along with any other images you might have added).

This post on Mastodon

In video posts, this is usually the poster image/thumbnail/preview image of the video. Which would be great, EXCEPT I want the video itself (as in, actually embedded) to be the main feature, not the video thumbnail. The above code removes the featured image from the media array, so the video gets embedded instead.