Archived topic
Edit 404 Page title and content.
13 replies · Started by Ika on January 28, 2021
Hi,
Hope you and your family in good health.
FYI, i'm, using GeneratePress' Artic theme and i intend to change the 404 page title and content.
i pasted these (refer below) onto code snippet plugin however the 404 still display the default title and content.
Pls advise what else i need to do to customise the 404 page.
Note:
i have also tried the 404 page plugin as recommended in the forum but still not able to customise the 404 page.
..........................................
add_filter( 'generate_404_title','generate_custom_404_title' );
function generate_custom_404_title()
{
return 'This is new title';
}
add_filter( 'generate_404_text','generate_custom_404_text' );
function generate_custom_404_text()
{
return 'this is new txt';
}
Hi there,
you can use a Block Element ( or hook element ) to create your 404 content:
https://docs.generatepress.com/article/block-element-overview/
Select the Custom Hook and add this: generate_do_template_part
Set the Display Rules to 404 page
Hi David,
Tq for prompt reply.
Here's what i did.
I created element (block).
Block type > Hook.
Custom Hook Name > generate_do_template_part
Location > 404 template
The 404 page still showing default title and text.
Any further advice pls.
Can you share a link to the site ?
Hi David,
I've created temp login access. Details below (private info area).
Tq for your time.
That login is not working for me - can you check the details and resend ?
Roger David.
I've created a new one (which i have tested as well) - refer below.
Can you disable the 404 plugin and any other functions that may be redirecting the 404 template.
Done David, i've deactivated these plugins > Redirection, 404page and coming soon/maintenance plugin.
Aah you have this CSS:
.error404 #page {
display: none;
}
which is hiding your Hook. I forced a 404 by going to a link that doesn't exist and removed that CSS in developers tools and the element is displaying.
Tq so much spending your time on this David.
I did similar test like yours ie by pasting a url of post that no longer exist. The custom error message appears.
However, the Default Message appears if search not found (i.e when i try to search sth using the search box). I tested this after i've cleaned cache and did it in incognito mode just to be sure.
Your advice pls.
Aah No Results is a completely differ template - it uses the search template, but there is no display rule for that. Instead you would do this:
1. Remove the Display Rule location. So there is no location chosen.
2. Examine the Blocks Elements URL and get the ID eg. 10
3. Save the Element
4. Then you will need to add this PHP Snippet to your site:
add_filter( 'generate_block_element_display', function( $display, $element_id ) {
if ( 10 === $element_id && is_search() ) {
global $wp_query;
if ( ! $wp_query->found_posts ) {
$display = true;
}
}
return $display;
}, 10, 2 );
Change the 10 in the code to match your block elements ID.
Adding PHP:
https://docs.generatepress.com/article/adding-php/
You've been a great help David.
That works.
Tq, tq so much.
Have a nice day David and be safe.
Awesome - glad to be of help