问题描述
我已经为我的WordPress网站构建了404页。在我的404.PHP
中,我使用<?PHP get_header(); ?>
调用标头函数。我想用404徽标替换我的常规徽标。在我的header.PHP
中添加以下功能:
<?PHP
if ( is_404()){
echo "test";
}
else {
echo "test1";
}
?>
这仅用于测试我是否可以对404页执行其他操作并且可以正常工作。
现在,我要替换404页的徽标。在两种情况下,徽标均为svg
。
这是header.PHP
的相关部分:
<header class="m-header">
<div class="m-header-content">
<div class="m-header-logo">
<a href="/">
<svg>
<title>test<title>
<path class="st0" d="svgpath....."/>
</svg>
</a>
</div>
<div>
<?PHP wp_nav_menu( array(
'theme_location' => 'main_menu','container_class' => 'm-header-menu') );
?>
</header>
有人可以举一个例子,说明如何使用顶部的功能更改<svg>
吗?或者有人可以给我有关它的文档。
解决方法
例如,您可以在header.php
处的标记中使用条件
<?php if (is_404()) { ?>
// Your 404 svg markup here.
<svg>
<title>404 Logo<title>
<path class="st0" d="svgpath....."/>
</svg>
<?php else { ?>
// Your regular logo svg here.
<svg>
<title>Site Logo<title>
<path class="st0" d="svgpath....."/>
</svg>
<?php } ?>
在提供的标头标记中,您可以这样应用-
<header class="m-header">
<div class="m-header-content">
<div class="m-header-logo">
<a href="/">
<?php if ( is_404() ) { ?>
// Your 404 svg markup here.
<svg>
<title>404 Logo<title>
<path class="st0" d="svgpath....."/>
</svg>
<?php else { ?>
// Your regular logo svg here.
<svg>
<title>Site Logo<title>
<path class="st0" d="svgpath....."/>
</svg>
<?php } ?>
</a>
</div>
<div>
<?php wp_nav_menu( array(
'theme_location' => 'main_menu','container_class' => 'm-header-menu') );
?>
</header>
P.S。如果格式不正确,请通过电话回答。 希望这可以帮助helps
,假设顶部的404函数执行正确的操作,则应该可以执行类似的操作。
->
SVG路径HTML作为字符串,请确保引号已转义[ " ] -> [ \" ]
<header class="m-header">
<div class="m-header-content">
<div class="m-header-logo">
<svg>
<?php
if ( is_404()){
echo "<title>404 svg</title>";
echo "<path class=\"st0\" d=\"svgpath.....\"/>"; // 404 SVG Path
} else {
echo "regular svg";
echo "<path class=\"st0\" d=\"svgpath.....\"/>"; // SVG Path
}
?>
</svg>
</a>
</div>
<div>
<?php wp_nav_menu( array(
'theme_location' => 'main_menu','container_class' => 'm-header-menu') );
?>
</header>