嘿,伙计们,我想把博客标题改成图片。
这就是我想要达到的
我尝试将这段代码添加到css中,它正在工作。
.rh-content {
text-indent: -9999px;
background: url(http:file-location.png) 10px 10px no-repeat;
/* height: 100%; */
}
但这就是结果
图像显示得不够。另外,我还想在我的子主题中将它添加到functions.php中。我试过这段代码
add_filter('the_title', function($title){
$title = '' .
$title;
return $title;
}); ?>
但这就是结果。这就是我在添加过滤器函数时所看到的
这是原始代码
"first_name)." ".esc_attr($userdata->last_name); ?>"
这是网址链接。https://harborllc.wpengine.com/blogs/
非常感谢各位
发布于 2018-02-16 01:04:14
使用the_title
过滤器的问题是,过滤器应用于任何地方的任何标题的所有用途,因此您将每个帖子和页面的标题设置为图像。您应该使用传递给过滤器的第二个参数$id
,只将您的更改应用于所需的标题:
function wpse_294263_title_image( $title, $id ) {
if ( $id === 2 ) {
$title = '';
}
return $title;
}
add_filter( 'the_title', 'wpse_294263_title_image' );
2
应该是标题所属页面的ID。如果将页面设置为Settings > Reading中的Posts页面,则可以使用get_option( 'page_for_posts' )
动态设置该页面。
CSS实现的问题是将图像设置为背景,但不适合元素的背景或调整元素的大小以适应背景。您可能希望将两者混合在一起:
.rh-content {
text-indent: -9999px;
background: url(http:file-location.png) left center / contain no-repeat;
height: 100px;
}
contain
值在background
中确保背景图像的大小与背景相适应,而不管元素大小如何,而height: 100px
则调整该大小,从而使图像成为合理的大小。
发布于 2018-02-16 15:56:25
我只是改变了内容
jQuery(function($) {
$('.rh-content h1').replaceWith(function(){
return $('', {
html: this.innerHTML
})
})
});
https://wordpress.stackexchange.com/questions/294263
复制