Updating the_post content is only working with Twenty Twenty theme

As your code looks quite generic, the obvious answer and thing to debug is that either the if condition is not true when you’re expecting it to be, or $media_content isn’t getting generated as you expect.

Are you 100% sure that on all the other sites the post_type is 'my_custom_post_type' when you expect it to be?

You can debug things like this by temporarily inserting code like:

function my_custom_post_type_the_post($post_object)
{
    $post_object->post_content = "debug: " . ( $post_object->post_type == 'my_custom_post_type' ? "yes" : "no" ) . $post_object->post_content;

    $media_content_test = generate_media_content( ... ); // make this stuff self contained so it's easy to test

    $post_object->post_content = "debug: " . $media_content_test . $post_object->post_content;

    // original code below

    // The post object is passed to this hook by reference so there is no need to return a value.
    if(

This way you know things like:

  • The hook definitely ran?
  • The conditions you were expecting are actually true or not
  • The output you were expecting is getting generated properly