- This topic has 29 replies, 4 voices, and was last updated 4 years, 6 months ago by Leo.
-
AuthorPosts
-
October 16, 2019 at 10:40 am #1036495Matias
Hi, Im tryig to add this code to make a custom 404 page in funtions.php file of a GP child Theme:
/* CUSTOM 404 PAGE */
add_filter( ‘generate_404_title’,’generate_custom_404_title’ );
function generate_custom_404_title()
{
return ‘Custom 404 title’;
}
add_filter( ‘generate_404_text’,’generate_custom_404_text’ );
function generate_custom_404_text()
{
return ‘Custom 404 text’;
}But I always get a WordPress Error when I try to load the web
How can add code un funtions.php file without problems?
thanksOctober 16, 2019 at 11:20 am #1036536DavidStaffCustomer SupportHi there,
can’t see a problem with that code.
What is the error ?
And can you try using the Code Snippets plugin to test, if that errors then there is something conflicting.October 16, 2019 at 11:30 am #1036544MatiasThanks for your answer.
I rather not use more plugins in my wordpress site.
I just add the code in funtions file and when I try to load the website I get a WordPress Error.
Blank Page with that errorOctober 16, 2019 at 11:38 am #1036555DavidStaffCustomer SupportYou don’t need to keep the plugin installed – it would be good if you can test the code using the plugin – if the error doesn’t happen then there is something else causing the issue. Just trying to narrow down where the issue could be
October 17, 2019 at 2:35 am #1036985MatiasOctober 17, 2019 at 5:48 am #1037087DavidStaffCustomer SupportDo you have any other functions in your child theme?
If so can you try removing the others to see if there is a conflict.October 17, 2019 at 8:54 am #1037352MatiasI have the generatepress folder with all files and a generatepress_child folder with 3 files:
functions.php, screeshot.jpg and style.cssThe functions.php file content is:
<?php /** * GeneratePress child theme functions and definitions. * * Add your custom PHP in this file. * Only edit this file if you have direct access to it on your server (to fix errors if they happen). */ function generatepress_child_enqueue_scripts() { if ( is_rtl() ) { wp_enqueue_style( 'generatepress-rtl', trailingslashit( get_template_directory_uri() ) . 'rtl.css' ); } } add_action( 'wp_enqueue_scripts', 'generatepress_child_enqueue_scripts', 100 );
All works fine but if I add some php code after the last line the error appears.
October 17, 2019 at 8:00 pm #1037724TomLead DeveloperLead DeveloperHi there,
Can you try this as your functions.php file?:
<?php /** * GeneratePress child theme functions and definitions. * * Add your custom PHP in this file. * Only edit this file if you have direct access to it on your server (to fix errors if they happen). */ add_action( 'wp_enqueue_scripts', 'generatepress_child_enqueue_scripts', 100 ); function generatepress_child_enqueue_scripts() { if ( is_rtl() ) { wp_enqueue_style( 'generatepress-rtl', trailingslashit( get_template_directory_uri() ) . 'rtl.css' ); } } add_filter( 'generate_404_title', function() { return 'Custom 404 title'; } ); add_filter( 'generate_404_text', function() { return 'Custom 404 text'; } );
Let me know 🙂
October 18, 2019 at 1:42 am #1037883MatiasHi, I have added this code to my functions.php file in GP Child Theme with the same result
Loading a webpage or opening the WP admin Panel the error reappears.
October 18, 2019 at 8:58 am #1038285MatiasPlease any help?
I have this functions file in child theme:
<?php /** * GeneratePress child theme functions and definitions. * * Add your custom PHP in this file. * Only edit this file if you have direct access to it on your server (to fix errors if they happen). */ function generatepress_child_enqueue_scripts() { if ( is_rtl() ) { wp_enqueue_style( 'generatepress-rtl', trailingslashit( get_template_directory_uri() ) . 'rtl.css' ); } } add_action( 'wp_enqueue_scripts', 'generatepress_child_enqueue_scripts', 100 );
I add some php code like this:
`<?php/**
* GeneratePress child theme functions and definitions.
*
* Add your custom PHP in this file.
* Only edit this file if you have direct access to it on your server (to fix errors if they happen).
*/
function generatepress_child_enqueue_scripts() {
if ( is_rtl() ) {
wp_enqueue_style( ‘generatepress-rtl’, trailingslashit( get_template_directory_uri() ) . ‘rtl.css’ );
}
}
add_action( ‘wp_enqueue_scripts’, ‘generatepress_child_enqueue_scripts’, 100 );
add_filter( ‘generate_google_font_display’, function() {
return ‘swap’;
} );`And I get a WordPress tecnichal problem adviser. Check you mail to test…
Always the same error
October 18, 2019 at 9:54 am #1038332TomLead DeveloperLead DeveloperWhat’s the specific error? It should give you some sort of hint at what’s going on.
October 18, 2019 at 10:20 am #1038346MatiasYou can see a imagen of the problem in this post:
PostI open the functions.php of the child theme
I add after the last line a php code like this:add_filter( ‘generate_google_font_display’, function() { return ‘swap’; } );
And when I reload my web site I get a WordPress > Error
The site is experiencing technical difficulties.
October 18, 2019 at 7:47 pm #1038558TomLead DeveloperLead DeveloperThat’s not the specific error, though. You should receive an email with more details, which should have the specific error.
If not, you can check the
error_log
file on your server, which should have a specific error. It’s hard to debug without knowing what we’re looking for.Alternatively, you can try the
functions.php
file in our child theme: https://docs.generatepress.com/article/using-child-theme/Then you can add your functions one by one until it breaks.
October 19, 2019 at 1:52 am #1038714MatiasThe error email says:
An error of type E_PARSE occurred on line 1 of the file /home/tecnoped/public_html/tecnopeda.com/wp-content/themes/generatepress_child/functions.php. Error message: syntax error, unexpected ‘function’ (T_FUNCTION)
October 19, 2019 at 10:43 am #1039082TomLead DeveloperLead DeveloperCan you try our child theme I linked to? Then just add your functions to it one by one – I’m thinking there might be some sort of funky character in yours.
-
AuthorPosts
- You must be logged in to reply to this topic.