Hook to replace custom tags in block showing related articles
This is not easy to solve in preprocess, it is better to do this earlier when the view() of the node is executed, for example:

function mymodule_NODE_view_alter(&amp;$build) {
    if ( isset($build['body']['0']['#text']) ) {
      $build['body']['0']['#text'] = replace_tags_in_content($build['body']['0']['#text']);
    }
}


This works, no matter if the node is used as page or in views (as content).

You might run into caching issues, when you make changes, that are not coming from the database and drupal does not know, which cache tags have to be invalidated. This would be a version of this code to address this:

function mymodule_NODE_view_alter(&amp;$build) {
    $nocache = false;
    if ( isset($build['body']['0']['#text']) ) {
      $build['body']['0']['#text'] = replace_tags_in_content($build['body']['0']['#text'], $nocache);
    }
    if ( $nocache ) {
      $build['#cache']['max-age'] = 0;
    }
}


You have to set $nocache in the function replace_tags_in_content($string, &amp;$nocache) to true, if you change dynamic data from outside.