You should try this:
function replace_tag($string){
$search = array('<p>', '</p>');
$replace = array('<h2>', '</h2>');
echo str_replace($search, $replace, $string);
return $string;
}
add_filter('the_excerpt', 'replace_tag');
or this:
function replace_tag($string){
$replace = array(
'<p>' => '<h2>',
'</p>' => '</h2>'
);
$string = str_replace(array_keys($replace), $replace, $string);
return $string;
}
add_filter('the_excerpt', 'replace_tag');