【发布时间】:2018-09-21 20:39:06
【问题描述】:
我正在尝试用图像替换 WordPress 网站页面标题上的文本。我正在本地使用儿童主题。我还需要能够分别定位每个页面,因为图像会有所不同。
我想在 Photoshop 中设计一些自定义标题并将它们保存为 Jpg/Png,然后替换文本。
我想我已经确定了 CSS 的正确部分
.hestia-title{
}
我试过了
.hestia-title{
font-size: 0px;
background-image:url(assets/img/quick_test.jpg);
}
这使它看起来像这样:
谁能指出我正确的方向?谢谢
使用此代码:
.page-id-88 .page-header .hestia-title{
color:transparent;
background-image: url(assets/img/title_mock.png);
}
.page-header.header-small .hestia-title{
background-size:contain;
background-repeat: no-repeat;
}
.home .hestia-title{
display:none;
}
这是page.php的内容
<?php
/**
* The template for displaying all single posts and attachments.
*
* @package Hestia
* @since Hestia 1.0
*/
get_header();
do_action( 'hestia_before_single_page_wrapper' );
?>
<div class="<?php echo hestia_layout(); ?>">
<?php
$class_to_add = '';
if ( class_exists( 'WooCommerce' ) && ! is_cart() ) {
$class_to_add = 'blog-post-wrapper';
}
?>
<div class="blog-post <?php esc_attr( $class_to_add ); ?>">
<div class="container">
<?php
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', 'page' );
endwhile;
else :
get_template_part( 'template-parts/content', 'none' );
endif;
?>
</div>
</div>
<?php get_footer(); ?>
【问题讨论】:
-
试试
color: transparent -
谢谢,当我添加 .page-header .hestia-title{color:transparent;} 这使文本消失了!图像似乎被拉伸到一定大小。这和利润有关吗?
-
图像会适应您的盒子的大小,因此如果您想要特定的尺寸,您必须为盒子指定尺寸(
with和heght)和background-size: cover和background-repeat: no-repeat。如果您希望图像在任何尺寸下看起来都完整,则必须将其放入background-size: contain和background-repeat: no-repeat -
注意:如果您不删除
标签并将其放在其他位置,替换文本将对您的 SEO 不利。 - 否则,如果您只想将文本作为文本的背景 - 您可以创建一个带有图像选择器的元框并在您的 php.ini 中使用它。这可以通过 ACF(高级自定义字段)或自己创建来完成 - 这样您就可以拥有特定页面的特定图像。 -
只知道,
<h>标签上的display:none是谷歌用来指示页面内容的主要指标,在最坏的情况下可能会导致谷歌搜索被禁止。 - 不显示本身对 SEO 来说还不错,但是试图用大量隐藏的标签来破坏你的页面排名是危险的。 - 也无需担心 - 只有 1 个 <h1>标签,不要隐藏它。
标签: css wordpress image parent-child