开发者

Wordpress: Can 404.php page send values to header.php?

Is it possible to place code in the 404.php file which will change elements in the header.php file?

For example开发者_如何学编程, if a 404.php page is loaded, I want the page's title and description to be filled in with specific values.

However, as it is these values are empty.


Yes, like objects said:

An example of your header.php:

<html>
<head>
    <title><?php if(is_home()) { echo "Home"; } elseif(is_404()) { echo "Error!"; } elseif(is_page()) { echo "Page"; } elseif(is_single()) { echo "single"; } else { "Anything else"; } ?></title>
</head>
<body>

WordPress Hooks are very easy to use


Depends on your header.php. If it has hardcoded title and description then you're not going to be able to change.

So the answer is really in your header.php of your theme and how it handles displaying the title.

You can use the is_404() function (in your header.php) to test if it is a 404 and display the appropriate title.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜