• Just created a child theme, as I had made some modifications to a theme that I didn’t want to lose. I copied all the themes files into a different directory and reinstalled the theme. now I get this error –
    Fatal error: Cannot redeclare register_scripts() (previously declared in /homepages/23/d236124545/htdocs/wp-content/themes/childbelle/functions.php:16) in /homepages/23/d236124545/htdocs/wp-content/themes/belle/functions.php on line 27

    can’t think what might be causing it, especially as I replaced the functions.php file only yesterday

    Edit: Moved all the files back into original directory (including modified child theme style.css file, and its all working again.
    What is going on? and if the theme is updated will i still lose my modifications?

Viewing 15 replies - 1 through 15 (of 33 total)
  • You’ve redeclared a function definition for a function called register_scripts().

    The first problem is that the Parent Theme uses a way too generic function name. Such a function should be named themename_register_scripts().

    The second problem is that this function apparently isn’t intended to be “pluggable” by Child Themes (e.g. by being wrapped in a if ( function_exists() ) conditional).

    The solution is either:

    1) Simply don’t re-declare this function. Based on the name, I’m guessing that you can let the Parent Theme handle registering of scripts.

    or

    2) If you must register your own scripts, do it in a function with a different name, such as childbelle_register_scripts().

    Thread Starter dbphte1

    (@dbphte1)

    sorry but im a complete newbie, haven’t been using wordpress a full week, not sure i 100% understand what youre saying.
    if i made a child theme, but left out the functions.php would that save all my changes from updates and not cause that same error to happen? and if i did this should i still change register_scripts() to themename_register_scripts()?

    First: never change anything in a Theme you don’t control, if you want to take advantage of automatic updates for that Theme.

    Second: a Child Theme should only incorporate the things being changed in the Parent Theme, and nothing more. If you’re only making CSS changes, then you only need a style.css in your Child Theme. If you modify the footer markup, then include footer.php in your Child Theme. Etc.

    Thread Starter dbphte1

    (@dbphte1)

    oops, i’ve made a few changes, nothing major, like removing page titles from pages and putting an RSS button in the sidebar, (i can’t work out how to do anything more complex)but this means I should be able to do them again pretty quickly in the event of an update. I’ll be sure to keep backed up files just in case.
    Also, is there anything generic i should avoid putting in the child theme apart from functions.php, or are these things theme specific?

    Also, is there anything generic i should avoid putting in the child theme apart from functions.php, or are these things theme specific?

    That question is pretty much Theme-specific. The functions.php file is very powerful. You can do almost anything with it – so be very careful.

    You can override any template file from the Parent Theme by including it in the Child Theme; the only caveat is that you have to maintain any Parent-Theme changes to those template files.

    So, for example, if you copied page.php into your Child Theme, so that you could remove the Page Titles, when the Parent Theme is updated, you’ll need to make sure that you incorporate any other changes to the updated version of the Parent Theme’s page.php template file into the Child Theme’s version.

    Some Themes are designed to be more Child-Theme friendly than others, by breaking out the template files into various template part files, or by using custom hooks – which means that you have less code maintenance to worry about on each Theme update.

    Thread Starter dbphte1

    (@dbphte1)

    so how can I break up the files? I’m assuming its more complicated that cutting and pasting?
    I’ve not come across hooks yet, how would i use them?

    You can’t break up the template files, unless the Parent Theme is already set up that way.

    Same thing with hooks: you can only use them if the Parent Theme defines them.

    Thread Starter dbphte1

    (@dbphte1)

    But if i change them in the parent theme, and it updates, bad stuff happens? idk anything about this, sorry

    But if i change them in the parent theme, and it updates, bad stuff happens? idk anything about this, sorry

    Right; that’s why you never change the Parent Theme.

    Thread Starter dbphte1

    (@dbphte1)

    ah.
    so my best course of action is to create a child theme without any of the files i definitely haven’t changed, and just deal with any updates as and when they happen?

    so my best course of action is to create a child theme without any of the files i definitely haven’t changed, and just deal with any updates as and when they happen?

    Exactly!

    Thread Starter dbphte1

    (@dbphte1)

    thanks man, massive help ??

    Thread Starter dbphte1

    (@dbphte1)

    not sure if this is the right place to post this, or if i should have started another thread, but anyway.
    so i made a child theme, its working fine, but i’m having an issue. the original theme had had some colour scheme css files that you couldn’t access through the dashboard editor, so I was using ftp to change them. i put those files in my child theme, presuming they’d control the colour schemes for the child. however, they don’t. I was going to see whether changing the file for the parent would work, but the directory has vanished. the child theme works just fine, and wordpress says I have the theme installed, but there is no directory for it.

    tbh i’d be happy if you could tell me how to link the colour scheme files to the child theme, but if anyone knows whats going on with the directory that would be smashing as well.
    https://blog.getseenings.co.uk/ is the site, i was trying to change the little blue bar in the footer, and the image source was in blue.css

    Have you tried using @import to include the custom color-scheme CSS files in your Child Theme’s style.css?

    Thread Starter dbphte1

    (@dbphte1)

    no, how would i do that?

Viewing 15 replies - 1 through 15 (of 33 total)
  • The topic ‘child theme – fatal error, seemed to be fine before’ is closed to new replies.