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

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

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

Viewing 14 posts - 1 through 14 (of 14 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

    No problem πŸ™‚

    #1683111
    Yvette

    Hi,

    Is making my digital webshop and now has my first products with your good assistance and templates. Today I got a warning from Google complaining about No global identifier provided (e.g., gtin, mpn, isbn) among others.

    Has on WordPress.org found some data language to put into funtions.php file. As recommended above I have now installed Code Snippets and pasted inn the text.

    The thing is, when I go into funtions.php file for GP at my host one.com nothing is changed there. In my WP dashboard I see a button for export. Do you thing all is good or should I export something?

    Is putting the data language below in case you need it:

    /**
    * Use SKU as gtin8 in structured data
    */
    add_filter( ‘woocommerce_structured_data_product’,’add_gtin8′,10,2);
    function add_gtin8( $markup, $product ) {
    $markup[‘gtin8’] = str_replace(‘-‘, ”,$markup[‘sku’]);
    return $markup;
    };

    webpage is omaco.no (not finished so you will recognise GP and Mikes Search and Shop:))

    #1683151
    David
    Staff
    Customer Support

    Hi there,

    when you add code to Code Snippets it doesn’t add this the functions.php – it creates its own space for that code.

    #1683373
    Yvette

    Okidoki. Thanks/YB

    #1683437
    David
    Staff
    Customer Support

    You’re welcome

    #1689555
    Yvette

    Hi again,

    Been thinking a bit.

    Will it be possible to make a snippets only for one one products, in this example:
    https://www.omaco.no/produkt/semrush/

    If I write markup language for the specific woo-commerce product or page, does the code get instructions to where it should be implemented?

    Or should one instead use elements and hooks to get it to a specific page or something simpler if possible?

    #1689908
    David
    Staff
    Customer Support

    Can you raise a new topic – where we can help with that query directly as this topic is resolved πŸ™‚

    #1838581
    Charles

    Adding to this thread:

    I was told to put this code in the bottom of my functions.php file:

    add_filter( ‘searchwp\indexer\alternate’, ‘__return_true’ );

    I did that by creating a new snippet in the code-snippets plugin.

    But it doesn’t seem to be doing what I expected. I guess I don’t understand if it matters where you place the code. If you put it in code-snippets is that the same as putting it in functions.php?

    thanks!

    #1838604
    David
    Staff
    Customer Support

    Hi there,

    its kinda the same thing as adding it to the functions.php accept the way that code snippets stores the code.
    Make sure the code yo added is exactly the same as that provided by the plugin author.

    Specifically single quote marks eg. they should be straight quotes like so: ' NOT curly like this: β€˜

    If its still an issue you may want to check with the plugin author.

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