[Resolved] Adding to functions.php (no child theme)

Home Forums Support Adding to functions.php (no child theme)

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1037380
    sofia

    Hey there!

    I am upgrading my website theme to GeneratePress and trying to move all my existing snippets and tracking codes over (currently working on a staging copy). I have a piece of code to add to the functions.php file but when I go to the theme editor it’s saying “Please do not make any edits to this file. All edits should be done in a child theme.”

    But I don’t have any child theme. I’m using the Generatepress theme and the Pro plugin and just customizing things from scratch. In the Themes, the only theme that’s active is Generatepress.

    The code I want to add relates to a social share plugin, to force Pinterest hidden images to be excluded from lazy loading. the code is included in my old theme so I am not sure why I can’t place it in the functions.php of the new theme. Is there another location?
    Also, I’d prefer not to have to use a plugin to add this code.
    Thank you so much!

    #1037387
    Leo
    Staff
    Customer Support

    Hi there,

    It’s never a good idea to add modify the theme core files like style.css or functions.php as they will be erased during updates.

    Try using one of the methods here instead:
    https://docs.generatepress.com/article/adding-php/

    I’d say Code Snippets is the easiest solution and we use it all the time.

    If not the next best option is the child theme’s functions.php.

    Let me know if this helps 🙂

    #1037401
    sofia

    Hi Leo,

    Thank you for your quick response.
    As I said before I am not using a Child theme, so I was confused when I read I can only add it to the child theme. Do you mean one of those site library themes? because I’m not using any of those.

    I looked at that article before… So if I add that plugin, can I delete it after the code is added?
    The reason I am changing my theme is to help speed up my website which has been extremely slow on my last theme and part of that was also removing unnecessary plugins… that’s why I asked 🙂

    Thank you

    #1037407
    Leo
    Staff
    Customer Support

    It would be a blank child theme:
    https://docs.generatepress.com/article/using-child-theme

    No you cannot remove the plugin and keep the code activated. The plugin should have very minimal impact to your site speed.

    You can run your site through speed test before and after.

    #1037412
    sofia

    Ohh I see! thank you so much. I’m gonna check out the articles now and try the plugin also.

    Sofia

    #1037414
    Leo
    Staff
    Customer Support
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.