如何在wordpress中显示图像内置the_title()?

时间:2016-03-14 06:28:31

标签: php wordpress wordpress-theming

我想在wordpres内置函数the_title()中显示图像。请帮忙 我的代码:

<?php the_title( '<h3 class="entry-title"><img src="<?php echo (get_template_directory_uri()); ?>/images/line.png">','<img src="<?php echo (get_template_directory_uri()); ?>/images/line.png"></h3>' ); ?>

2 个答案:

答案 0 :(得分:3)

the_title()的工作原理如下:

svn merge -c -REV .

默认情况下为<?php the_title( $before, $after, $echo ); ?> ,因此只需传递$echo = true$before

像这样使用:

$after

如果在标题之前和之后都需要图像,请使用以下代码:

<?php the_title( '<h3 class="entry-title"><img src="'.get_template_directory_uri().'/images/line.png">','</h3>' ); ?>

答案 1 :(得分:0)

如果您想在项目的所有标题中添加图片,那么我们的the_title过滤器会更好 (在给定的代码中,get_template_directory_uri()用于父主题,如果你在子主题中工作,那么你必须用“get_stylesheet_directory_uri()”来改变它。)

function add_image( $title) {

$src = get_template_directory_uri().'/assests/images/header.jpg';

return $title.'<img src=" '.$src.' ">';

} add_filter('the_title','add_image',10);

相关问题