একটি theme-এর file সরাসরি edit করা কাজ করে, যতক্ষণ না theme update হয় — প্রতিটি সরাসরি edit চুপচাপ overwrite হয়ে যায়। একটি child theme একটি parent theme থেকে সবকিছু inherit করে, একই সাথে customization একটি আলাদা folder-এ রাখে যা update process কখনো ছোঁয় না।
শুধু দুটি file দরকার — সম্পর্ক declare করা একটি stylesheet, আর একটি functions file।
/* wp-content/themes/my-child-theme/style.css */
/*
Theme Name: My Child Theme
Template: wgh-starter
Version: 1.0
*/Template: লাইন — ঠিক parent theme-এর folder নামের সাথে মেলা — এটাকে একটি standalone theme-এর বদলে একটি child theme বানায়।
Default-এ একটি child theme-এর নিজের style.css parent-এরটাকে সম্পূর্ণ replace করে — এর CSS স্পষ্টভাবে load করা দরকার, তারপর দরকার হলে যেকোনো কিছু override করতে child-এর নিজের rule এর পরে enqueue করা।
// wp-content/themes/my-child-theme/functions.php
function wgh_child_enqueue_styles() {
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
wp_enqueue_style('child-style', get_stylesheet_uri(), ['parent-style']);
}
add_action('wp_enqueue_scripts', 'wgh_child_enqueue_styles');| Function | সবসময় যা নির্দেশ করে |
|---|---|
| get_template_directory() | parent theme-এর folder |
| get_stylesheet_directory() | active theme-এর folder — একটি child theme active থাকলে সেটা |
Child theme-এ ঠিক একই নাম আর path দিয়ে একটি file রাখলে শুধু সেই একটা file override হয় — বাকি প্রতিটি template তখনো parent থেকে আসে, অপরিবর্তিত।
my-child-theme/
├── style.css
├── functions.php
└── single.php ← শুধু এই template override হয়; page.php, index.php, ইত্যাদি তখনো parent থেকে load হয়কখন এটার জন্য যাবেন
একটি child theme site-এর জন্য বানানো না এমন একটি theme-এ যেকোনো পরিবর্তন করার standard, নিরাপদ উপায় — একটি কেনা বা download করা theme সহ যার update স্বাভাবিকভাবে কাজ করতে থাকা দরকার।