Move parent themes customization into child theme - wordpress

I have an ecommerce site's header and footer built using drag and drop builder. When I shift the parent theme to child theme, all of the customization of drag and drop are lost. What could be a way to load a child theme without losing the parent theme customization?

Unfortunately, the Problem is each theme saves its data separately in a different row of the same table either it's parent or child. WordPress treats them as a single theme. So, you have to again re-create child theme. You can do it faster as you know what modifications were done.
For more information.
get the settings into the child theme
Child themes should inherit parent theme customizer settings on activation / switching
Child themes should inherit parent theme customizer settings on activation / switching
Hope this will helps you.

OK, so from what I understand is that this problem is dependent on how the parent theme you start with has been programmed. I happened to encounter this problem with the WP twentyseventeen theme, which I might have expected it to handle the theme_mods_ options better.
Anyway, one of the links listed by Sunil had a post written by Laura Kohan identified a couple of database entries that contianed all of the customizer options related to the child theme. In my case, I am using the twentyseventeen theme as the parent, and I was only able to identify one database entry that was pertinent to the situation and seemed to store relevant data about the child theme, and that was the theme_mods_twentyseventeen_child option in the wp_options table of the database. I noticed that the theme_mods_twentyseventeen option contained all the customizations from the parent in the form of a long array, so I simply decided to copy that array to the child's field. Of course, it would be smart to, save the child theme_mods_ option in a text file, or elsewhere before overwriting it with the parent data, but, for me, getting the customizations that I wanted was as simple as that...
For those people who don't know how to access the database, BEWARE!, changing data like this is not usually a good idea. You have to be very careful because often, some database entries will reference other entries, and it can get really messy. In fact this entry references custom_css_post_id, and possibly some others that you may want to consider carefully if you want keep the value from the child ID or use the one from the parent... But to point you in the right direction, most web hosting services will have PHPMyAdmin available for you in the cpanel, from there you can view your database, and from there find the table called wp_options, in which you'll find the relevant entries/options. And like Laura's situation, other themes may have some other extra entries to consider so be careful with that as well.
I think there might be a better way of directing WP to use a particular set of "mod" options in the child functions.php file, but so far I have not seen a good example of that. It would be nice to see some examples for: (1) referencing the parent mod options, (2) referencing the child specific mod options, and (3) copying the parent mods to the child mods. (another link by GreenShady in Sunil's post had some code that looked like it might do the copying, but I couldn't get it to work, perhaps someone else can provide a better example.)
Anyway, good luck...

Related

what is the difference between parent theme and child theme

A client asked me to redesign her web site, built several years ago in WP by another developer. Although I've never worked with WP before, I'm pretty comfortable with html, css, and php, and I more or less understand how WP stores content and dynamically builds pages. But I'm wondering how to approach these challenges:
My client's site has about 75 pages. There are about 25 that are static (i.e. the content changes infrequently if at all; things like "about us" and "faqs") and there are about 50 pages that are more "blog-like", except that instead of posts, the content contains directory-type info (e.g. 12 DJs in the area) or event-related info (e.g. upcoming shows at local theaters). Both of these categories contain many sub (and sometimes sub-sub) categories (e.g. medical services > pediatric > kid allergy specialists) and the content updates fairly frequently.
I understand the difference in WP between "pages" and "posts". But I need to find out the best way to structure the static content. Should I just set up a parent/child hierarchy of pages, changing the permalinks to something that makes sense? Or is it better / easier to just build the static pages outside WP and somehow link to them from the common navigation?
As a web designer, I want to "wow" my client with a great design. While there are loads of wonderful WP themes available, I really need to create something unique. But I'm wary of breaking something, so what's the best way to take an existing theme and just tweak it enough to make it look a little different?
Finally, other than mounting a massive "copy and paste" effort when the new site is built, is there a way to transfer content from the original site to the new one?
I would create a Child Theme (https://www.hostinger.com/tutorials/how-to-create-wordpress-child-theme). And just do your changes in this theme.
You can download the complete Website with a plugin like duplicator and install it local (xampp).
Is hard to give you the right way. There are so many ways a theme can look like. Different page builder plugins or Advanced Custom Fields.
Maybe the only thing you can do, is to update (Theme, Plugin)everything and lift the page. Especially if it is a purchased theme with any page builder. But don't change anything in the main theme. Create a child theme!
I understand the difference in WP between "pages" and "posts". But I
need to find out the best way to structure the static content. Should
I just set up a parent/child hierarchy of pages, changing the
permalinks to something that makes sense? Or is it better / easier to
just build the static pages outside WP and somehow link to them from
the common navigation?
It's not something like that. Consider the child theme as inherited (like a PHP class) from the parent theme. Imagine every .php file in a child theme is like overriding a function from parent class which is parent theme in this example.
For more information check the codex out or google "wordpress theme vs child theme" there are lots of articles explaining the difference.

The proper way of developing child themes

I am going to develop a child theme based on Canvas by WooThemes and I have one simple question: Since a lot can be configured from the theme admin panel, should I use that, rather than pure css in the child theme? For example, if I was to set the body background, should I do it like that, or would it be more recommended to write a single rule of css?
If you can finish everything up in the theme panel, there's no need to write a child theme.
If you have other reasons for writing it, however, keep in mind that options (i.e., everything you do in the admin panel) will not transfer to other sites. Changes you make in the stylesheet will travel with your theme.
Ah you know creating child theme is really good when you want to update your sites time to time.
When you want to make different version of the sites you can make child theme. Do whatever changes in your styles and push to update the theme.

Where can I add functions to WordPress, not related to the theme?

Here's the situation: There's a WordPress plugin in place that enables a mobile-friendly theme if a mobile User Agent is found (with the usual details and logic, not important).
This mobile theme is copied from the plugin directory, into another, and overwritten when updates to the plugin come out.
I need to provide some extra custom functions for the theme, but don't want to put all of the code directly in the mobile plugin/theme, because it may get overwritten.
I think the best thing might be to put my special/custom functions into their own plugin, and deal with the theme-specific changes as they come up - that way there's less to diff/compare when updates come out.
What do you think is the best approach with something like this? Is there a safe alternative to creating my own plugin, where I can store some custom code?
You could make a wordpress child theme, so that if the parent theme gets updated all your changes remain intact. From the above link:
...the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)
That should allow you to do what you need to do.

Is it safe to switch theme in drupal on my site?

I have a website with Drupal CMS behind it. I use a custom theme and I would like to change it but I am not sure if it is entirely safe, i.e. is it possible to lose some data, design, etc if I switch it back to my theme? What about blocks and their position if the theme uses different blocks layout. Thanks.
It should be safe, but you should have a current backup of the database and files anyways. You can (and probably should) set the administration theme to one of the standard themes, so you can't lock yourself out of the admin section if you break your custom theme.
If the regions are named different (or missing in one theme) you may have to move your blocks. The blocks are set seperately for every theme, so just enable the second theme (without setting it a default) and set the blocks for this theme. After that you can set the theme as default.
I use a copy of the website to try out bigger changes to the site, so that I never break the live site. It makes it much easier and safer to just try out stuff.
Blocks are configured per theme. You won't lose any data.
You will not lose any data but your block positioning may change depending on how the theme is set up.
Like some others have said, you won't lose data, but I've typically had to position the blocks when changing themes.
If you enable the new theme (don't set it to default yet) you can setup the blocks before you go live with it. And if you allow certain users to change themes, you can view and tweak it.
Like everyone else said, you will not lose data. I would like to add if you switch from a theme that has, say two columns, to a one column theme, the blocks from the second column will have to go somewhere (they would need to be manually set).
You won't lose any data, though you might have to re-position the blocks as per the new theme layout.

What do you prefer ? Writing a Wordpress plugin or child theme?

What think to be consider when you prefer coding a solution in form of child theme rather then in form of a plugin ?
Themes and plugins solve different problems: plugins are for business logic, themes for presentation. They are not interchangeable. I prefer the right tool for the right job. :)
i prefer in child theme (or in function.php), rather then in form of plugin. It's more easy to reuse. You can just move it from one theme to another.
Any generic functions should be in a plugin. That way, they are available to all themes, and if you make changes in one place, you don't have to copy and paste to several files.
The benefit of a child theme is that you can make changes to an existing theme, such as twentyten, without directly modifying the source code, which is fragile -- it can cause errors and has to be repeated every time the theme is updated.
Depends on the situation. If it's something that could readily be used by any (or many) different sites regardless of the theme, I do a plugin.
If it's something specific to This Particular Site Only, I would probably put it in the child theme's functions.php. Even if specific to the one particular site only, I might make it a plugin if it's something I might want to turn on and off later.
Other than the fact that you can turn plugins on and off, there is little if any difference between code in a plugin and code in functions.php.
If it's something most easily coded straight into the theme (e.g. a particular permutation of the_loop) then of course just do it in the theme template and put supporting code in functions.php

Resources