I'm new to WordPress but realize that themes can be updated which will cause you to loose any customization you have made.
For the site I'm working on at the moment, I have copied the theme, by changing it's folder name & the name at the top of the style.css in the comments. I then uploaded it to the server.
Since then I have learnt that you can make child themes.
Which is better practice, is their any advantages or disadvantages to either approach? Is it possible that the changes which I have made to my copied theme will get over ridden? The only major changes I have made to my copied theme have been to the style.css & header.php.
If you're only making minor changes, then you should use a child theme. This has several advantages:
You get free updates whenever the parent theme is updated. This includes security updates, which could be very important.
Your code base will be much more manageable.
You will also find it easier to apply your alterations to other themes.
Related
Hoping someone experienced could share his knowledge and expertise on this. I was trying to find a good explanation on how to not lose customisations from my theme after an update, but I still cannot find a guide, without telling me to have a child theme before the customisations. However, I read them too late, and when hired freelancers, they have done the customisations on the parent theme files.
I am now running on a child theme, but, unfortunately, few of my customisations have been done before the move and they are still on the parent theme.
My thinking is can I:
"extract" locally my customisations,
update the theme,
copy back the customisations to the functions.php? (parent or child this time)
The extracting, can I do it: by comparing the code in e.g. Sourcetree: my customised parent functions.php with the original file I downloaded at the very start? (attached screenshot)enter image description here
When copying back the customisations - can I copy it to the child functions.php instead of the parent file?
What about customisations that have been done on different files other than functions.php and style.css - how can I find which other files have been altered in the parent files or know which one I should manually alter?
Will customisations on plugin files stay the same and not break the plugins after the update?
Thank you!
Here's one slightly crude/basic idea:
Create a repo/directory, add a copy of the original parent theme to it (at the same version of the one you modified (the whole theme, unmodified original copy)).
Now dump your modified parent theme in to the same directory. Agree to replace any existing files.
Now view the changes between each file via a GIT client such as Sourcetree or TowerApp
This will let you know what differences there are across all files.
Functions.php:
Now you can see which changes there are betweeen the original parent and your modified versions, you can copy function.php changes to your child-theme/functions.php file yes.
I have downloaded a theme but would like to edit the PHP files, but there is a theme editor block. I can't access it by typing the theme editor into the url, I just wondered if there is a way of getting around it.
It is highly discouraged to edit themes like that, because any changes made that way will be deleted upon update. The recommended way is to create a child theme and edit your PHP CSS and HTML there.
By using a child theme you will ensure that your modifications are
preserved.
Using a child theme can speed up development time.
Using a child theme is a great way to learn about WordPress theme development.
all the documentation to create a child theme is here Wordpress Codex
You will have to open functions.php for that theme outside of wp-admin. Like in a text editor or ide and upload it back to your themes folder.
I am creating a drupal theme and use role theme switcher to change the theme according to user role
for the the role anonymous I've created a custom theme
the theme html script does not change whatever the changes I make
I've cleared the cache from performance
remove the cache from administrator->performance clear cache
change the default theme to new and fresh theme ( I am using zen) and run module and its custom theme
it may need modification in css or js files
Heed Drupal's unofficial moto when developing a theme:
Also, there are many base themes (Zen for instance) which have a setting to clear the cache on every page request during theme development. You turn this off once the theme is completed, but it's a nice feature when you're still working on things to avoid caching issues.
I have the following problem. I have to modify a JQuery function into a file named custom.js into the theme that I am using for my website.
I have no problem to implement my customization to the function but my doubt is: What will happen when the theme will be updated in the future?
I am pretty sure that the file will be overwrite and that I will lost my customization.
How can I prevent this situation and maintein my customization?
What you're doing is forking the theme. Nothing complicated to deal with.
You should consider using a VCS like git or svn to monitor the changes you've made from the original theme, so you can apply them more easily to the latest released versions that the theme might have in the future.
You're right! All changes made to the parent theme will be lost on updating. Nevertheless, it is not a good practice to mess with the parent theme / core WordPress files. You never know where one may go wrong.
WordPress recommends the use of Child Themes for modifying an existing theme.
Note that this method is easier compared to the Version Control mechanisms like git or SVN. Moreover you could keep track of all the changes made by you.
Now that you're using the child theme, its easier to dequeue the custom.js file included by your parent theme using the wp_dequeue_script function. Then, use wp_enqueue_script to enqueue the file in your child theme with the necessary customization made.
I'd like to restrict a child theme to only being visible to me, the admin, for development purposes. Then I can make changes, upload and view them live and on the site without other people seeing those unfinished changes. Once I'm done, I take the affected files and move them to the Parent Theme's folder to make the changes visible to everyone.
Is this possible with some kind of script through functions.php?
And I'm not just talking about enqueuing the style.css file, I'm talking about setting up a complete child theme with sidebar.php, header.php etc. and only have the child theme files being loaded for me, the admin, for development purposes. Perhaps a way to define the child theme directory, embedded inside a condition that checks whether the user is admin.
Thank you :)
There is a plugin that does what you are looking for called Theme Test Drive. I haven't used it before but I think it uses some filters to update the theme at runtime for logged-in admin users.
Essentially, you install your new theme and activate it using the plugin instead of the theme switcher in the admin.