How to replace get_the_excerpt with first N words of post article while stripping html

As you can see from the source of get_the_excerpt there is a filter toward the end to modify the result. This is probably the most future proof approach. If at some point the blog will have manually written excerpts, these will be used. That would not be the case if you write a custom function for the twitter card. So, let’s start here:

add_filter ('get_the_excerpt', 'wpse312463_custom_excerpt');

Now there are three things you want to do: remove shortcodes, remove html and limit the amount of words. Here we go:

function wpse312463_custom_excerpt ($excerpt, $post) {
  if (empty ($excerpt)) $excerpt = $post->content;
  $excerpt = strip_tags (strip_shortcodes ($excerpt));
  $excerpt = wp_trim_words ($excerpt, 55);
  return $excerpt;
  }

You could even pack the last three lines into one statement, but that isn’t very readable.