- This topic has 13 replies, 3 voices, and was last updated 2 years, 10 months ago by David.
-
AuthorPosts
-
October 17, 2019 at 9:26 am #1037380sofia
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!October 17, 2019 at 9:43 am #1037387LeoStaffCustomer SupportHi there,
It’s never a good idea to add modify the theme core files like
style.css
orfunctions.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 π
October 17, 2019 at 9:52 am #1037401sofiaHi 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
October 17, 2019 at 9:55 am #1037407LeoStaffCustomer SupportIt would be a blank child theme:
https://docs.generatepress.com/article/using-child-themeNo 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.
October 17, 2019 at 9:57 am #1037412sofiaOhh I see! thank you so much. I’m gonna check out the articles now and try the plugin also.
Sofia
October 17, 2019 at 9:58 am #1037414LeoStaffCustomer SupportNo problem π
March 5, 2021 at 6:11 am #1683111YvetteHi,
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:))
March 5, 2021 at 6:43 am #1683151DavidStaffCustomer SupportHi there,
when you add code to Code Snippets it doesn’t add this the functions.php – it creates its own space for that code.
March 5, 2021 at 7:18 am #1683373YvetteOkidoki. Thanks/YB
March 5, 2021 at 8:10 am #1683437DavidStaffCustomer SupportYou’re welcome
March 10, 2021 at 6:40 am #1689555YvetteHi 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?
March 10, 2021 at 8:31 am #1689908DavidStaffCustomer SupportCan you raise a new topic – where we can help with that query directly as this topic is resolved π
June 29, 2021 at 6:50 am #1838581CharlesAdding 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!
June 29, 2021 at 7:14 am #1838604DavidStaffCustomer SupportHi 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.
-
AuthorPosts
- You must be logged in to reply to this topic.