If you take a look at the source code of get_the_excerpt
you see that there actually two arguments passed to the filter: the excerpt text and the post object. Your are only passing the text, while you need the post object to know the permalink.
So you should change these lines:
add_filter('get_the_excerpt', 'my_custom_wp_trim_excerpt', 99, 1);
function my_custom_wp_trim_excerpt($text) {
to:
add_filter('get_the_excerpt', 'my_custom_wp_trim_excerpt', 99, 2);
function my_custom_wp_trim_excerpt($text,$post) {
Now you have the post object available in your filter function and you can use get_permalink($post)
to retrieve the link to the post and do whatever you like with it. For instance like this:
function my_custom_wp_trim_excerpt($text) {
if(''==$text) {
$text= preg_replace('/\s/', ' ', wp_strip_all_tags(get_the_content('')));
$text= explode(' ', $text, 56);
array_pop($text);
$text= implode(' ', $text);
}
$text = $text . '<a href="' . get_permalink($post) . '">Link to post</a>';
return $text; }