Site logo

Archived topic

Adding PHP in funtions file of Child Theme

29 replies · Started by Matias on October 16, 2019

Viewing posts 16–30 of 30

Im using the Child theme downloaded from GP Help Documents and works great.
Troubles starts when I add some php code in

Any PHP code? Or just a specific function?

Exemple, If I add this one:

add_filter( ‘generate_google_font_display’, function() {
return ‘swap’;
} );

I get a error

Can you try this:

add_filter( 'generate_google_font_display', function() {
    return 'swap';
} );

the difference is the upright apostrophes .....

Nothing.
I have copied your code to the function file in GP child Theme and the problems follows

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)

Just tried the exact snippet and didn't receive an error.

Are there any other functions in the file?

No, just the code of the original functions File of GP Child Theme

Can you take a screenshot of your function.php file?

You can upload it using a service like this:
https://postimages.org/

This is de code in the functions File of the GP Child Theme downloaded from Help docs in GP site

<?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 );

The error is saying line 1, and line 1 is this: <?php

There definitely isn't an error there.

What program are you using to edit the file? Maybe there's some sort of encoding issue going on with the program/language you're using?

Notepad++
I havent had problems adding code in function with Genesis Framework, but I will check it

Checked and the problems still follows
Notepad++ is in UTF8 and ANSI encoding and I got the same error

Something must be corrupt, as the error is pointing to line 1, which is the opening PHP tag: <?php

Maybe your FTP program? It's super hard to guess like this, unfortunately.

If you use the same functions in the Code Snippets plugin, do they work?

Yes, with Code Snippets works fine.

Can I add the functions with the plugins and disable it them?

Unfortunately not.

The snippets would be deactivate when the plugin is disabled.

This archived topic is closed to new replies.