In child theme the file functions.php is an important file. Contrary to other files, it don’t “cancel” the functions available in functions.php of parent theme. Be aware of that !
With this below example (used in dev.xiligroup.com), some important things will be presented :
<?php /* functions for child of twentyten */ function twentyxilidev_setup () { register_nav_menus( array( 'top-primary' => __( 'Top-Primary Navigation', 'twentyten' ) ) ); load_theme_textdomain( 'twentyten', STYLESHEETPATH . '/langs' ); $xili_functionsfolder = get_stylesheet_directory() . '/functions-xili' ; if (file_exists($xili_functionsfolder . '/multilingual-functions.php') && class_exists('xili_language')) { require_once ($xili_functionsfolder . '/multilingual-functions.php'); } } /* actions */ add_action( 'after_setup_theme', 'twentyxilidev_setup', 11 ); // after the parent add_action('wp_head', 'special_head'); if(!is_admin()) { add_action('wp_print_scripts', 'xilifloom_theme_header'); add_action( 'wp_print_scripts','scripts_add',20 ); } define('XILI_CATS_ALL','0'); function special_head() { global $post; // for sliding // to change search form of widget if ( is_front_page() || is_category() || is_search() ) add_filter('get_search_form', my_langs_in_search_form,10,1); // in multilingual-functions.php } // .... |
The first function ‘twentyxilidev_setup’ call by the action after_setup_theme is important. Inside, a nav menu area is added. By re-loading text domain, the files .mo inside subfolder of child are used.
This add_action must called after the others: so order is set to 11 or more.
In extract of ‘special_head’, a filter incorporate a new radio-button series under the search input.
In this file, it is also possible to cancel widget spaces or menus space if necessary.
Here the functions.php of the twentyten-xili theme delivered in next post soon :
<?php /** * * */ function twentyten_xilidev_setup () { load_theme_textdomain( 'twentyten', STYLESHEETPATH . '/langs' ); // now use .mo of child $xili_functionsfolder = get_stylesheet_directory() . '/functions-xili' ; if (file_exists($xili_functionsfolder . '/multilingual-functions.php') && class_exists('xili_language')) { require_once ($xili_functionsfolder . '/multilingual-functions.php'); } } /* actions */ add_action( 'after_setup_theme', 'twentyten_xilidev_setup', 11 ); add_action( 'wp_head', 'special_head' ); define('XILI_CATS_ALL','0'); /** * * */ function special_head() { // to change search form of widget if ( is_front_page() || is_category() || is_search() ) add_filter('get_search_form', my_langs_in_search_form,10,1); // in multilingual-functions.php } /** * * */ function single_lang_dir($post_id) { $langdir = ((function_exists('get_cur_post_lang_dir')) ? get_cur_post_lang_dir($post_id) : array()); if ( isset($langdir['direction']) ) return $langdir['direction']; } ?> |
Next episode soon…
Pingback: Child theme : the file style.css | xili-plugins for multilingual sites