Site logo

Archived topic

Preserving CSS and PHP file Edits with a Fresh Site Library Install

7 replies · Started by Zoltan on May 2, 2022

Viewing posts 1–8 of 8

Hello GP Team,

I have imported the Marketer template from the Site Library, for a brand new site.

I need to do some important changes and additions in 'style.css', 'functions.php', and 'header.php' (For example I need to add google tag manager in header.php)

Since I am doing these edits on the original website template (as it was imported) and not on a child version,

How could I preserve and keep my style.css', 'functions.php', and 'header.php' edits even after a GP theme update, please?

Thanks,

Zoltan

Hi Leo,

Thank you, my rationale for a using a child theme is based on the following benefits for my WordPress sites:

I. Keeping Changes After Updates. One of the biggest problems with modifying a theme is when updates occur, all changes are wiped out.
II. Keeping Original theme files Safe, another big one, not tampering with the original theme files.
III. Easier to Modify Popular Themes on a child theme and these can be easier replicated across sites.

These are the initial changes I am looking to make (a few more expected later on as the site grows):

1. style.css: I need to add various styling changes that align the table of contents container, style and align bullet points, center the logo on mobile, styling hyperlinks, center align and style CTA buttons and some more. (I have all this CSS ready from another GP website that is using a GP child theme, but is not using the 'Marketer' site library template)

2.header.php: I want to add: Google Tag Manager, and the Ahrefs site verification tag.

3.functions.php: modify published on date and updated on date information

I would like to *safely* and *securely* make all of the above changes to the 'Marketer' template please, that I just imported from the site library,

Thanks for your help!

Zoltan

Hi Zoltan,

1. Code added through Appearance > Customize > Additional CSS remain through updates.

Reference: https://docs.generatepress.com/article/adding-css/#additional-css

2. The Google Tag Manager code as mentioned by Leo can be simply added through a Hook Element hooked to wp_head.

Reference: https://docs.generatepress.com/article/implement-google-tag-manager/

3. You can simply use a lightweight plugin like Code Snippets to add custom PHP.

Reference: https://docs.generatepress.com/article/adding-php/#code-snippets

These are all safe and secure methods, wherein even if there is an update, these changes should remain.

With these said, using a Child theme shouldn’t be needed, and as mention in this article, https://docs.generatepress.com/article/using-child-theme/, "if all you’ll be doing is adding CSS or PHP, a child theme probably isn’t necessary".

Hope this clarifies. :)

Hi Fernando, Hi @David,

Fernando,I disagree with you on 3 points you made, and your first point is completely wrong. Please do not take it personally, but I would prefer to get advice from @David on this one.

1. Code added through Appearance > Customize > Additional CSS DOES NOT remain through updates.

"The only time you risk losing changes is when you make them to the parent theme files or use the Additional CSS field from WordPress."
source: https://docs.generatepress.com/article/using-child-theme/

2. that works fine for me

3. Disagree, every plugin is "lightweight" nowadays for marketing, but I don't need another plugin for my website just to add PHP...

4. I also disagree "With these said, using a Child theme shouldn’t be needed" - Adding a large amount of CSS is much easier to implement on a child theme, rather than in the tiny additional CSS box.Plus as mentioned in 1. these do not remain after updates. Which does warrant the need for a child theme...

Hi @David,

I have listed a large number of CSS & PHP changes I plan to make to a fresh ‘Marketer’ template website.
What is the best way to go about this, so I am not losing all the CSS changes (from additional CSS, contrary to what Fernando mentions) and not installing any extra plugins (like Fernando mentions) for making PHP changes?

Thanks,
Zoltan

Hi there,

1. Additional CSS is stored as a custom_css post type in your database using the Theme name as its slug.
This means the CSS only gets loaded if that theme is enabled. So before switching themes you should copy any CSS over to the other theme.

BUT updates made to the theme will NOT remove or affect Additional CSS as its saved in your database.

Reading the rest of the topic it sounds like you should install a Child Theme. So you can move the CSS to styles.css and add your PHP snippets to functions.php. If thats the plan then i recommend you use FTP to access your server so you can edit / update those files remotely.

Hi David,

Thank you for the quick reply, appreciate it.

This is really helpful and I will follow your recommendation on the child theme and use FTP to access the server for the edits.

Thanks,

Zoltan

You're welcome glad we could be of help

This archived topic is closed to new replies.