admin管理员组

文章数量:1391951

I want to replace the

-tag around the_excerpt.

Right now html-output looks like this: <p> ...content of the excerpt... </p>

I want to achieve this: <h2> ...content of the excerpt... </h2>

I tried to use the following code in the content-page.php but it does not change anything.

<?php the_excerpt( '<h2>', '</h2>' ); ?>

Do you have any suggestions?

I want to replace the

-tag around the_excerpt.

Right now html-output looks like this: <p> ...content of the excerpt... </p>

I want to achieve this: <h2> ...content of the excerpt... </h2>

I tried to use the following code in the content-page.php but it does not change anything.

<?php the_excerpt( '<h2>', '</h2>' ); ?>

Do you have any suggestions?

Share Improve this question asked Mar 7, 2020 at 14:16 paelzerpaelzer 233 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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');

本文标签: htmlReplace ltpgttag in theexcerpt