WordPress.org

Forums

[resolved] fatal error in functions.php after tweaking a la Neil Patel (15 posts)

  1. professorblue
    Member
    Posted 1 year ago #

    Hi,

    I was working on my site - http://professorblue.com, following some instructions in Neil Patel's SEO guide (as seen here: http://www.quicksprout.com/the-advanced-guide-to-seo-chapter-4/

    and everything went swimmingly, until I followed his suggestion #3 which says to place this code at the bottom of my functions.php file:

    Add a rel="nofollow" to the comment reply links

    function add_nofollow_to_reply_link( $link ) {
    return str_replace( '")\'>', '")\' rel=\'nofollow\'>', $link );
    }

    add_filter( 'comment_reply_link', 'add_nofollow_to_reply_link' );

    I hit the UPDATE FILE button and then got this message:
    Fatal error: Call to undefined function once() in /home/content/74/9853474/html/wp-content/themes/shaken-grid-free/functions.php on line 325

    I have never had any trouble with my theme before tinkering with the functions.php file, so am guessing that ... it was the tinkering to cause this.

    I downloaded a fresh copy of the theme, opened up the functions.php file, copied it and then pasted it back into my existing functions.php file but can't get the error message to go away.

    What are my options to fix this?

    Thanks in advance for any help.

  2. Tara
    Volunteer Moderator
    Posted 1 year ago #

    problem seems to be with your "shaken-grid-free".

    - To rule out any theme-specific issue, try switching to the unedited default theme for a moment using the WP dashboard. If you don't have access to your admin area, you can switch to the default theme by renaming your current theme's folder in wp-content/themes and adding "-old" to the end of the folder name using via FTP or SFTP or whatever file management application your host provides. Alternately, you can remove other themes except the default theme. That will force your site to use it.

    If that does not help, contact the developers of your theme.

  3. From the looks of it, you put

    once('theme_admin/includes/widgets.php');

    instead of the proper

    include_once('theme_admin/includes/widgets.php');

    at the bottom of your functions.php file.

  4. professorblue
    Member
    Posted 1 year ago #

    Scriptrunner, how do you know I did this?

    I removed that part (wasn't sure if that was part of the instrux from Patel's page or if it was an example of what the end of the page in functions.php looked like).

    It's not there now, and I still can't save the file without the error.

    Tara, I'm going to try what you suggest.

    Thanks to you both.
    PB

  5. Obviously (from the error you got), there is no function called once(), but there is indeed one called included_once(). So I looked at the link you posted and saw that there was indeed an include_once() line that he said to put in your functions.php, except I didn't see a way to cut-and-paste it. So I guessed maybe you typo'd it :)

  6. You still need

    include_once('theme_admin/includes/widgets.php');

    and make sure

    Add a rel="nofollow" to the comment reply links

    is not in your code. That's just part of the article, not the code.

  7. professorblue
    Member
    Posted 1 year ago #

    Yeah I guess those instrux on the Patel page weren't clear for someone who doesn't know php.

    I added this in to the bottom of the functions.php:

    function add_nofollow_to_reply_link( $link ) {
    return str_replace( '")\'>', '")\' rel=\'nofollow\'>', $link );
    }

    add_filter( 'comment_reply_link', 'add_nofollow_to_reply_link' );

    include_once('theme_admin/includes/widgets.php');

    ?>

    Still get the same error message.

    I even used fetch to install a new functions.php directly to the server....same problem.

    It seems as if because I screwed up once, it's locked in to that? Is there a way to override it?

  8. Tara
    Volunteer Moderator
    Posted 1 year ago #

    Have you attempted switching to the default theme as I suggested before?

    If that does not help, try:
    - deactivating ALL plugins temporarily to see if this resolves the problem. If this works, re-activate them individually (one-by-one) to find the problematic plugin(s). If you can't get into your admin dashboard, try deactivating via FTP or SFTP or whatever file management application your host provides. If applicable, also remember to deactivate any plugins in the mu-plugins folder. The easiest way is to rename that folder to mu-plugins-old.
    - resetting the plugins folder by FTP or PhpMyAdmin. Sometimes, an apparently inactive plugin can still cause problems (because the hooks remain unless plugins completely removed or some plugins stick around in cached files. So by renaming the folder, you break them and force them inactive).
    - If the above troubleshooting steps fail to resolve the issue, try manually re-uploading all files and folders EXCEPT the wp-config.php file and the /wp-content/ directory from a fresh download of WordPress. Make sure that you delete the old copies of files & folder before uploading the new ones. Read the Manual Update directions first!
    - Always backup everything (including your database) before doing any actions, just in case.

  9. Are you sure you updated your theme's functions.php with the original, and in the right location?

    wp-content/themes/shaken-grid-free/functions.php

    Or are you using any caching plugins?

    It's obvious from the output that you haven't actually updated your active theme's functions.php file with the original (I assume you are uploading a backup).

    I think we're pretty sure it's this theme since you modified the functions.php yourself. If nothing else, just reintall the entire theme from scratch.

  10. You want to make sure that you make a backup of any theme file you modify so you can quickly restore if you create an error with your modifications. Or having the original, unmodified theme handy will work too.

  11. After rereading that section of the article, the only thing you should add at the bottom of functions.php is:

    // Add a rel="nofollow" to the comment reply links
    
    function add_nofollow_to_reply_link( $link ) {
    	return str_replace( '")\'>', '")\' rel=\'nofollow\'>', $link );
    }
    
    add_filter( 'comment_reply_link', 'add_nofollow_to_reply_link' );

    Don't use

    include_once('theme_admin/includes/widgets.php');

    It's clear to me now in the example he's saying put your code below this already existing line. (which is confusing, because that's what it is with whatever theme he's using, but it might not be there with your theme)

    The article offers bad advice (IMHO) in using the admin editor (Appearance->editor) to modify your theme files because it's too easy to make a mistake and then create an error that you can only fix by using FTP, which you should have done to begin with. When I set up sites for clients, I almost always disable the admin editor.

  12. professorblue
    Member
    Posted 1 year ago #

    switch to the default theme by renaming your current theme's folder in wp-content/themes and adding "-old" to the end of the folder name using via FTP or SFTP or whatever file management application your host provides. Alternately, you can remove other themes except the default theme. That will force your site to use it.

    I tried that. Didn't work.

    ...deactivating ALL plugins temporarily to see if this resolves the problem. If this works,

    Tried it. The plugin folder is renamed. Did not work.

    - If the above troubleshooting steps fail to resolve the issue, try manually re-uploading all files and folders EXCEPT the wp-config.php file and the /wp-content/ directory from a fresh download of WordPress.

    Did that. No worky.

    Are you sure you updated your theme's functions.php with the original, and in the right location?

    Yes I updated in wp-content/themes/shaken-grid-free/functions.php

    Or are you using any caching plugins?

    No caching plugins. I was planning on using a plugin for that but didn't get around to it yet.

    It's obvious from the output that you haven't actually updated your active theme's functions.php file with the original (I assume you are uploading a backup).

    I actually went to the shaken developer's site, re-registered to download a fresh copy of the theme, and then took the functions.php from the fresh copy, and ftp'd it to wp-content/themes/shaken-grid-free/functions.php.

    I also removed all themes except for 2013. No no, no no, no.

    Seems like at this point I've hit the trifecta of some unclear advice, ignorance/typo on my part, theme combusting and maybe my server not liking any of this? Wait, that's more than trifecta. More like a comedy of errors, a murder of crows.

  13. professorblue
    Member
    Posted 1 year ago #

    OK human error was all mine. I was doing stuff via FTP in an old directory, forgetting that I had made professorblue.com my primary. Anyway, much, much appreciated for both of your input, especially this:

    Don't use

    include_once('theme_admin/includes/widgets.php');

    It's clear to me now in the example he's saying put your code below this already existing line. (which is confusing, because that's what it is with whatever theme he's using, but it might not be there with your theme)

    The article offers bad advice (IMHO) in using the admin editor (Appearance->editor) to modify your theme files because it's too easy to make a mistake and then create an error that you can only fix by using FTP, which you should have done to begin with. When I set up sites for clients, I almost always disable the admin editor.

    I learn best by doing some, reading some.

    You guys rock.

    No crows murdered in the apprehension of my runaway website.

  14. Tara
    Volunteer Moderator
    Posted 1 year ago #

    glad you got it sorted :-)

  15. professorblue
    Member
    Posted 1 year ago #

    Just a way to say thanks - you guys are welcome to a free download of our illustrated kids book. Professor Blue Top Secret Lab Journal.

    I have gotten tons of help in forums like this one and would like to repay the favor in the best way I know how.

    The offer's good for kindle or epub version, if you're so interested. I don't know if you've got kids or know any kids. Suitable for 6-11.

    enter in discount code: techno blast to get it free.

    epub:
    http://professorblue.com/downloads/get-epub-version-kids/

    kindle:
    http://professorblue.com/downloads/the-kindle-version-for-kids/

    Cheers.

Topic Closed

This topic has been closed to new replies.

About this Topic