What is a WordPress Child theme & how to customize WordPress Theme using WordPress Child theme?

We all know that a WordPress theme is a collection of template files which lets us change the user interface, design, look & feel of the site.

 

Have you created WordPress theme or have installed any free theme or commercial one, many of you have done this job and have also customized but the problem is created when you have customized the original theme files and the update of that theme is available and you never would like to update as your customization will get destroyed if you update that, but my recommendation is that you should always keep your plugins and themes updated to the latest version. So you should take care during the customization and never do the customization in original file and should create a child theme. But what does that mean, and how do you do it?

 

In WordPress 3. 0 or latest versions a new concept was added by WordPress core team and community named as “Child Theme”.

 

As per the WordPress Codex definition of Child Theme:

 

“A WordPress child theme is a theme that inherits the functionality of another theme, called the parent theme. 

Child theme allows you to modify, or add to the functionality of that parent theme. A child theme is the safest and easiest way to modify an existing theme, whether you want to make a few tiny changes or extensive changes. Instead of modifying the theme files directly, you can create a child theme and override within. “

 

How to work with WordPress Child Theme?

 

Let’s take an example; I’ll create a child theme for WordPress default ‘Twenty Twelve’ theme.

1) So in this case, to create a child theme, I have to create a new directory alongside the ‘Twenty Twelve’ theme’s directory called twentytwelve-child.
“twentytwelve-child” directory should be in parallel of original theme twentytwelve.

2) Create a style.css file under the ‘twentytwelve-child’ theme directory.

Put the below text in style.css file

[css autolinks=”false” classname=”myclass” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”true” title=”example-filename.php”]
/*
Theme Name: Twenty Twelve Child
Theme URI: http://wp. tutsplus.com/
Description: Child theme for Twenty Twelve
Author: Japh
Author URI: http://wp. tutsplus.com/author/japh
Template: twentytwelve
Version: 1. 0. 0
*/

// This @import line loads the stylesheet of parent theme
@import url(‘. . /twentytwelve/style.css’);

//Theme customization starts here
[/css]

There are two important parts here to notice:

Template: twentytwelve
It tells WordPress that this theme is a child theme of the ‘Twenty Twelve’ theme

@import url(“. . /twentytwelve/style.css”);
It loads the parent theme’s (twentytwelve in this case) style.css as a starting point

3) Now you can log into your WordPress dashboard and see your ‘Twenty Twelve Child’ theme there, and activate it.

4) Make further alterations & addition and you will found that these will automatically reflected on your website.

 

Just Done!!

 

Now always keep in mind that whenever you want to make a customization to your theme, does it in your child theme.

Files in your child theme override files of the same name in the parent theme. So any file from your parent theme you want to change, copy to your child theme & make your modifications there.

The same goes for any templates that may not be in your parent theme. You can add them in your child theme, and WordPress will use them.

One exception to these rules is the functions.php file. In this case, the functions.php file for the child theme is loaded first, followed by the functions.php file of the parent theme. So there’s no need to copy the functions.php file from the parent into the child, just start fresh in the child theme for that one.

This allows the child theme to have all the functionality from the parent theme. Parent themes can also make their function pluggable, which allows a child theme to override them.

 

Why should you use WordPress Child Themes?

 

1. Safe Updates

A child theme automatically inherits the parent theme’s features, styles, and templates. This allows you to make changes to your site using child themes without ever modifying the parent theme. When a new version of the parent theme available, you can safely update it as you know that all your modifications are saved in the child theme.

 

2. Easy to Extend
A child theme built on a powerful theme framework allows a great deal of flexibility without writing a lot of code. You can selectively modify only the template files and functions that you need without going through other template files. You can add new functionality and much more.

 

3. Fall-back Safe
When you are creating a complete theme you need to think about all the possible scenarios and code for them. However, when you are working on a child theme and you forget to code for something, then there is always the parent theme’s functionality available as the fallback option.

 

WordPress catchable Tools for Child Theme

 

One-Click Child Theme plugin built and tested for the latest WordPress 3.x version.It adds a menu link into your Admin “Themes” section to automatically build a child using your currently active theme.This is fantastic if you don’t want to mess with FTP and are looking to play around with some new ideas.You can also use Child Themify plugin for creating the child themes.

 

If you plan to edit these files within the admin panel you’ll also enjoy clearer syntax highlighting for that you can install the Advanced Code Editor for some much-improved functionality. This makes wading through PHP code blocks and HTML/CSS a whole lot more manageable.

 

Additional Resources & references

 

1. http://wp.tutsplus.com/tutorials/theme-development/child-themes-basics-and-creating-child-themes-in-wordpress/

2. http://www.hongkiat.com/blog/wordpress-child-themes-dev/

 

Hope this all helps.

 

How to Import Large XML File (WXR file) in WordPress

You all knows that WordPress comes with built in import/export functionality that allows you to import or export your WordPress posts in XML format.

 

Have you ever tried to move your blog from one server to another, I think you have done this many time. But I am pretty sure that you were stuck in case the WXR (XML) file is very large to import? I have also faced this one but after a little search on Google, I have found perfect solution & sharing the same with you, hope this will help you to save several minutes.

 

I am also sure that you have tried to fiddling with PHP variables to increase the upload size limit, but even then you might run into some sort of execution time-out. But in case of large file, your server admin may not even let you change these settings or will show timeout even after updating.

 

The perfect way is to split your huge WXR data file into smaller chunks.

 

Even though you can manually split your large XML files by creating multiple XML files with the same header, category, and footer information and dividing the rest of the items. But no one has time for that and obliviously it increases chances of mistakes? There is a very nice free tool that allows you to split your XML files with just a few clicks.

 

Version 1.52 of the WXR Splitter is here!
Download the below and split your large file in chunks automatically.

 

WordPress XML (WXR) splitter

 

WXR splitter comes with the features
1)  Super fast parsing of the WXR file.
2)  Files are split by file size rather than by number of lines or tags.

 

Minimum requirements for running the WXR splitter

Operating System: Windows XP, Windows Vista, or Windows 7 with the .NET 2.0 framework installed.
(If you don’t have it installed, you can download .NET 2.0 directly from Microsoft)

 

There is a similar WordPress WXR Split utility available for Mac users. Use the below link to download

 

Click here to Download

 

Still trouble with the tools? Or need more help, post your comment below.

what is difference between array_merge and array_combine in php

Difference between array_merge and array_combine in php

 

Array Merge

PHP: array_merge
Merge one or more arrays

 

Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one.
If the input arrays have the same string keys, then the later value for that key will overwrite the previous one or if the arrays contain numeric keys, then the later value will not overwrite the original value and will be appended.

 

Values in the input array with numeric keys will be renumbered with incrementing keys starting from zero in the result array.

 

Have a look on example below

 

Example:
<?php
$array1 = array(“color” => “red”, 2, 4);
$array2 = array(“a”, “b”, “color” => “green”, “shape” => “trapezoid”, 4);
$result = array_merge($array1, $array2);
print_r($result);
?>

 

Output will:
Array
(
[color] => green
[0] => 2
[1] => 4
[2] => a
[3] => b
[shape] => trapezoid
[4] => 4
)

 

Array Combine

PHP: array_combine
Creates an array by using one array for keys and another for its values

 

Example:
<?php
$array1 = array(“green”,”red”,”yellow”);
$array2 = array(“avocado”, “apple”, “banana”);
$result = array_combine($array1, $array2);
print_r($result);
?>

 

Output will:
Array
(
[green] => avocado
[red] => apple
[yellow] => banana
)

 

PHP: How to enable rewrite_mod in WAMP

Have a look on below Image and follow the steps to make “rewrite_mod” on WAMP server.

 

enable-rewrite_mod-wamp

 

You all know WAMP stands for (Windows, Apache, MySQL, PHP), It is package provide you an environment to execute your PHP application.

 

But the general issue you have faced with WAMP is, your rewrite rules usually not work i.e. .htaccess file is not read by Apache server (in WAMP) or give you error “Internal Server Error”.

 

You have to follow 2 simple steps to troubleshoot and fix the issue.

 

1) If you have installed WAMP on your system, then you can find a small icon in your task bar bottom right corner.

 

2) Click on that, you will see a menu as above

Go to
=>Apache
=>Apache Modules
=>click on rewrite_module
Check/tick marks that option, if you find it checked already that means it’s already enabled.

Save

Quickly Deactivate or Activate All WordPress Plugins via Database or FTP

WordPress plugin activate deactivate all at once and Quickly

Sometimes during troubleshooting, it’s recommend to deactivate all plugins and activate them one by one and suppose at that time you will not able to login in WordPress admin (wp-admin) or white screen of death. At the same point we need to disable all the plugin or some plugin then in that case, How will you disabled/deactivate all or some plugin manually by the database or using FTP. Some time we need it to do very quickly.
I am sharing with you the technique by which you can quickly disable and (re)enable your entire set of WordPress plugins.

 

Deactivate All Plugins Using FTP

 

Navigate to the “/wp-content/” folder. You will see a folder called plugins. Rename the plugins folder to anything like  “plugins-deactivate”. Once you do this, all of your plugins will be deactivated automatically.

 

There may be due to some issue with plugin and it locked out your admin panel. If the issue was with your plugin, you should be able login to your “/wp-admin/” after deactivating the plugin. Once you do that, go back to your /wp-content/ directory and rename “plugins-deactivate” back to plugins. You can troubleshoot the problem by activating plugin one by one until your site breaks again.

 

 

Deactivate all plugins using phpMyAdmin

 

Login to your database using with phpMyAdmin and then have a backup.
I always suggest you to take Backup before doing any updates in table directly, so please in first step take backup of your database.
If you have backup of your database, you can quickly restore that and can revert your changes, so in this case(if there will some accident) you will always in safe hands.

 

Now, search a row in “wp_options” table that have “option_name” as “active_plugins”. Use the following SQL query (update your Database table prefix “wp_” if needed) for doing the same job.

 

SELECT * FROM wp_options WHERE option_name = ‘active_plugins’;

 

Once you found active_plugins column, click to edit it. You will see something like the below, depends on the number and type of plugins you have installed:

 

a:13:{i:0;s:19:”akismet/akismet.php”;i:1;s:23:”all_in_one_seo_pack.php”;i:2;s:28:”breadcrumb-navigation-xt.php”;i:3;s:37:”contact-coldform/contact_coldform.php”;i:4;s:13:”feedcount.php”;i:5;s:36:”google-sitemap-generator/sitemap.php”;i:6;s:13:”gravatars.php”;i:7;s:30:”nofollow-free/nofollowfree.php”;i:8;s:17:”ol_feedburner.php”;i:9;s:26:”simple_recent_comments.php”;i:10;s:18:”simple_twitter.php”;i:11;s:9:”top10.php”;i:12;s:16:”wp-db-backup.php”;}

 

This is a serialized array, you can unserialize this array by simply using the tool “http://www.functions-online.com/unserialize.html“. Copy the above string and click on run button you will get an array that represents every activated plugin on your site.

 

Thus, to quickly disable all plugins without using the wp-admin is cut the serialize array string as we have seen above and paste it into a safe notepad (text) file. After removing the code, click the button to save your changes and that’s it. All WordPress plugins are now deactivated (although you have all the plugins files in the same place “wp-content/plugins” and you can activate the plugin whenever you want by wp-admin area- if found working). This above method is obviously handy during, when the situation is critical and time-sensitive. Once you are ready to re-enable your entire set of plugins, simply copy & paste the preserved code(serialized array string) by notepad file and put it in the “active_plugins” field. Click save and done.

 

If you want to activate only some of those, unserialize the array by the above tool and make the array of plugins you want to activate then serialize that and put the string in the “activate_plugins” columns.

 

You can also go with a very simple SQL query to disable all plugins in one second.

UPDATE wp_options SET option_value = ” WHERE option_name = ‘active_plugins’;

 

 

This method works only for WordPress older versions(2.9 or older) for later use the below.

UPDATE wp_options SET option_value = ‘a:0:{}’ WHERE option_name = ‘active_plugins’;