[Support request] Adding PHP in funtions file of Child Theme

Home Forums Support [Support request] Adding PHP in funtions file of Child Theme

Home Forums Support Adding PHP in funtions file of Child Theme

Viewing 15 posts - 16 through 30 (of 30 total)
  • Author
    Posts
  • #1039275
    Matias

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

    #1039314
    Tom
    Lead Developer
    Lead Developer

    Any PHP code? Or just a specific function?

    #1039415
    Matias

    Exemple, If I add this one:

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

    I get a error

    #1039462
    David
    Staff
    Customer Support

    Can you try this:

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

    the difference is the upright apostrophes …..

    #1040534
    Matias

    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)

    #1040684
    Leo
    Staff
    Customer Support

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

    Are there any other functions in the file?

    #1040691
    Matias

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

    #1040693
    Leo
    Staff
    Customer Support

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

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

    #1040694
    Matias

    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 );
    #1040786
    Tom
    Lead Developer
    Lead Developer

    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?

    #1040798
    Matias

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

    #1040822
    Matias

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

    #1041539
    Tom
    Lead Developer
    Lead Developer

    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?

    #1041617
    Matias

    Yes, with Code Snippets works fine.

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

    #1041622
    Leo
    Staff
    Customer Support

    Unfortunately not.

    The snippets would be deactivate when the plugin is disabled.

Viewing 15 posts - 16 through 30 (of 30 total)
  • You must be logged in to reply to this topic.