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 badges1 Answer
Reset to default 0You 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
版权声明:本文标题:html - Replace <p>-tag in the_excerpt 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744688835a2619867.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论