[Resolved] Error Adding Filter to Child Theme

Home Forums Support [Resolved] Error Adding Filter to Child Theme

Home Forums Support Error Adding Filter to Child Theme

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #367705
    Leon

    Hi Tom,

    I’m using child theme’s functions.php to add a filter. But after that, my website turns into a white blank page. 500 internal error.

    Those code are the ones I used to put in to functions.php in main theme and they worked before.

    Is there anything wrong with my method please?
    (right now I already restored the default functions.php file from your new black child theme to make the website work. But the function I needed was not added yet)

    Thank you
    Leon

    #367733
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Can you show me the function you’re adding?

    #367736
    Leon

    Yes.

    add_filter( 'upme_profile_display_user_pic', 'upme_profile_display_user_pic', 10, 2);
    function upme_profile_display_user_pic($display,$params){
        $display .= '<div class="upme-field upme-view upme-user_pic">
                         <div class="upme-field-type">
                             <i class="upme-icon-camera"></i>
                             <span>' . __('Profile Picture','upmehooks') .'</span>
                         </div>
                         <div class="upme-field-value">
                             <span><img src="' . get_user_meta($params['user_id'], $params['meta'] ,true) . '" /></span>
                         </div>
                      </div>';
        return $display;
    }

    It’s from this page: http://profileplugin.com/display-profile-picture-custom-field/

    #367737
    Tom
    Lead Developer
    Lead Developer

    Hmm, the code looks fine.

    Make sure the top of your functions.php file starts with: <?php

    Otherwise, use one of the methods here: https://docs.generatepress.com/article/adding-php/

    #367765
    Leon

    Hi Tom,

    Wierd. I put those code in functions.php file from GP main theme and it works.

    Code snippet causes white page also.

    Anyway, I’ll stick to it now as long as it works.

    Thanks for your time.
    Leon

    #368047
    Tom
    Lead Developer
    Lead Developer

    Putting it into the main theme isn’t the best method, as you’ll lose it when you update.

    If you check your error_log file, it should tell you the exact error.

    #368668
    Leon

    Hi Tom,

    I believe this is the error log for adding that filter to generatepress child theme.

    [17-Aug-2017 03:53:35 UTC] PHP Parse error: syntax error, unexpected ‘add_filter’ (T_STRING) in /home1/bestchi7/public_html/interpreterdatabase/wp-content/themes/generatepress_child/functions.php on line 1

    [17-Aug-2017 03:58:16 UTC] PHP Parse error: syntax error, unexpected end of file in /home1/bestchi7/public_html/interpreterdatabase/wp-content/themes/generatepress_child/functions.php on line 1

    [17-Aug-2017 04:22:27 UTC] PHP Parse error: syntax error, unexpected ‘add_filter’ (T_STRING) in /home1/bestchi7/public_html/interpreterdatabase/wp-content/themes/generatepress_child/functions.php on line 1

    Below error log for code snippet.

    [17-Aug-2017 07:21:03 UTC] PHP Warning: require_once(/home1/bestchi7/public_html/interpreterdatabase/wp-content/plugins/code-snippets/php/class-code-snippets.php): failed to open stream: No such file or directory in /home1/bestchi7/public_html/interpreterdatabase/wp-content/plugins/code-snippets/code-snippets.php on line 84
    [17-Aug-2017 07:21:03 UTC] PHP Fatal error: require_once(): Failed opening required ‘/home1/bestchi7/public_html/interpreterdatabase/wp-content/plugins/code-snippets/php/class-code-snippets.php’ (include_path=’.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear’) in /home1/bestchi7/public_html/interpreterdatabase/wp-content/plugins/code-snippets/code-snippets.php on line 84

    I never changed anything on line one of the child theme php file.

    Is there anything I was missing?

    Thanks again
    Leon

    #368783
    Tom
    Lead Developer
    Lead Developer

    Can you paste your entire child theme functions.php file (with the filter added) into a pastebin so I can check it out?: https://pastebin.com/

    #370556
    Leon

    Hi Tom,

    Sorry for the late reply. I was struggling with VPN these days as I can’t access your site directly from China.

    I will paste the code tomorrow.

    Appreciate your help.

    Leon

    #370576
    Tom
    Lead Developer
    Lead Developer

    No problem!

    #371011
    Leon

    Hi Tom,

    Kindly check this page for the child theme functions.php file after I paste the filter.
    https://pastebin.com/Sn0Eh7nw

    Regards
    Leon

    #371308
    Tom
    Lead Developer
    Lead Developer

    Hmm, nothing wrong there – just tried it in my test child theme.

    Can try removing everything except for the opening <?php, and save.

    Then re-add the code only.

    #371336
    Leon

    Thanks Tom. I tried it. Looks like it’s working now. I’ll wait for the next GP update and see if it still works. Right now I’m happy with it.

    Thank you so much for your patience and great help!
    Leon

    #371691
    Tom
    Lead Developer
    Lead Developer

    Glad I could help 🙂

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.