Hot answers tagged child-theme
18
Bare bone themes are great, personally I prefer them over frameworks. I have noticed that 'liking' one over another comes down to how it feels, so I would suggest trying several out until you find one. For instance a lot people like WordPress boilerplate but I could not get the hang of it. My current favorite is Handcrafted WP, since it very similar to my ...
17
You should run the code after theme setup.
function osu_twentyten_continue_reading_link() {
return ' <a href="'. get_permalink() . '">' . __( 'Read on <span class="meta-nav">→</span>', 'twentyten-child' ) . '</a>';
}
function osu_twentyten_auto_excerpt_more( $more ) {
return ' …' . ...
10
I like to do this as follows:
Go to underscores.me, fill out the theme name, and download the theme.
Strip out the parts of this (somewhat clean) template that don't want to use.
Start building your own template with the functionality that you wrote.
This way you will have a clean template to start with, and no core theme functionality provided by the ...
9
Theme workflow balance is combination of several factors:
amount of code, individual to sites
amount of code, shared between sites
incorporating upstream changes
Each of these can be important and each of these can be unimportant.
Parent theme model satisfies all of these reasonably well, but not very well. You get clear separation of shared and ...
8
Child Themes are useful for users who mainly want to make style changes to their Theme, but don't want - or know how - to maintain the underlying code. Grokking PHP/WordPress Theme Development is an entirely different thing than grokking CSS.
Child Themes are also useful for users who want to implement minor functional changes to their Theme. This is ...
8
I totally agree with Rarst. I just want to add some small things.
Note: I differentiate parent theme and framework. In my answer, I consider parent theme like TwentyEleven where it's mainly created for a specific website and less hooks than a framework.
Starter theme:
Pros
Easy to customize at HTML level. I mean something like open <div>, custom ...
7
One does not simply throw <link> (CSS) or <script> tags into the <head> of a WordPress theme.
The right way to do it: Register, enqueue ... tadaa!
WordPress has the "Dependency API" for this task. It consists basically out of those public functions:
wp_register_script()
wp_enqueue_script()
wp_register_style()
wp_enqueue_style()
Then ...
7
Leave a file with the name screenshot.png inside the root of your child theme folder and it works.
The recommended image size is 600x450. The screenshot will only be shown as 300x225, but the double-sized image allows for high-resolution viewing on HiDPI displays.
see on Codex
6
Child themes reference parent themes by directory name, and in a normal install all your themes live in wp-content/themes/, so I'd say it's fine to reference those themes by their relative path:
include '../parent-theme/some-file.php';
If that makes you uncomfortable, I observe the following constants in WordPress 3.0.1 with a twentyten child theme called ...
6
Kind of - the template_directory is the directory of your parent theme. The stylesheet_directory is the directory containing the primary stylesheet in use (which, if you have a child template will be the in the child directory, otherwise it will be in the template directory).
See the Codex here:
'stylesheet_url' - Returns the primary CSS (usually ...
6
In addition to Chip Bennets answer
Some developers like myself have their own custom frameworks or are using one like Genesis, Hybrid, etc. Those frameworks don't bundle too much styling, but more functionality like their own templating and hooking mechanisms. Sometimes also stuff like CPT or CT base classes, meta box libraries, css frameworks, etc. It's ...
6
Well, I'd say that you need a custom plugin. All the rationale is in this Q&A:
Where to put my code: plugin or functions.php?
Also related:
Where do I put the code snippets I found here or somewhere else on the web?
Create a Functionality Plugin Instead of Using Functions.php
And answering to the Question, create the following file ...
6
Use a plugin for that. Hook into after_setup_theme and check if the current theme is the correct child theme:
add_action( 'after_setup_theme', 'common_child_theme_functions' );
function common_child_theme_functions()
{
if ( 'Twenty Twelve' !== wp_get_theme()->parent() )
return;
// do your work
}
wp_get_theme() returns a WP_Theme ...
5
Expanding on @Rarst's answer, here's a more generic approach that is not tied to a specific theme, but can be used inside your own child theme's functions.php to nuke any parent theme page templates you want to get rid of.
function remove_template( $files_to_delete = array() ){
global $wp_themes;
// As convenience, allow a single value to be used ...
5
Overriding that template would be much easier than getting rid of it. Just the way logic goes.
I make no claim it's efficient idea (late here), but this would get it nuked from edit screen:
add_action('admin_head-post.php','remove_template');
function remove_template() {
global $wp_themes;
get_themes();
$templates = &$wp_themes['Twenty ...
5
Child themes only override files in the main theme directory (like header.php) that are called in with functions like get_template_part or get_header, etc.
The correct way to add scripts to WordPress is with wp_enqueue_script. If your parent theme uses this, you can override the JS files by using wp_dequeue_script and enqueuing your own.
Like so...
...
5
I am never sure about 'optimal approach' - however, I am using this in the functions.php in a child theme of Twenty Eleven
//deregister the header images of Twenty Eleven, and register a few new RAW header images//
add_action( 'after_setup_theme', 'raw_theme_header_images', 11 );
function raw_theme_header_images() {
unregister_default_headers( array( ...
5
You can only override functions in a Parent Theme if the Parent Theme makes functions pluggable (by wrapping them in an if ( ! function_exists( 'function_name' ) ) conditional), or if the output of a function is passed through a filter (e.g. return apply_filters( $filter_name, $function_output );
Pluggable functions: in the Child Theme's functions.php ...
5
One of the biggest uses for child themes is in MUWP instances. Often, in a multisite install, the related sites share some or most of the theme, but may need to have some custom page layouts or element styles. In this case, it makes a lot of sense to use child themes. Elements that are the same are addressed in the parent theme (which may in fact be a custom ...
5
Just FYI, this question probably borders on too localized, as it is specific to the Oenology Theme.
That said, here's where I think you're having a problem: Oenology enqueues two style sheets:
style.css, directly in the document head (thus before wp_head() is fired)
{varietal}.css, at wp_enqueue_scripts, with priority 11, in functions/dynamic-css.php:
...
4
functions.php file of the child theme is loaded before the functions.php of the parent theme so it's best to run the code at the hook after both themes are loaded. At the earliest at after_setup_theme hook so Change:
add_action('init', 'scherzo_scripts');
to:
add_action('after_setup_theme', 'scherzo_scripts');
4
My child theme inlcudes php as well as css files. Whenever I switch to a different theme for mobile browsers it works but the custom post types, cats etc are missing in action. I am kind of lost.
Your problem is that you're doing too much with the theme. Themes are all about presentation, not about functionality. If your child or parent theme is ...
4
Both the header and background image features setup some globals in order to work, unsetting those globals seems to have some effect, and at the least removes them from the administration side.
add_action('after_setup_theme', 'remove_theme_features', 11 );
function remove_theme_features() {
$GLOBALS['custom_background'] = 'kill_theme_features';
...
4
Looking at their demo source, the easiest way to do this is by styling page classes like pageid-69 or slug-example-page:
body.slug-example-page{
background: url(...);
}
If it has to be random image, add your styles in the header template so you can use PHP to generate dynamic css.
4
Hi using Function Reference/remove action and usingFunction Reference/remove filter.using these two functions only we can overriding the functions.
4
How do I remove a require_once admin panel from the parent theme from the child theme functions.php?
For cases where you want to require/include PHP files, but still allow child themes to replace those PHP files outright, then you should use the locate_template function.
Example: Parent does this:
locate_template( 'admin/file.php', true );
This finds the admin/file.php file in either the child or the parent theme, then does a require on it (that's what ...
4
Try this out. Remove the already added shortcode then add the new shortcode on the init hook.
function shortcode_cleaner() {
remove_shortcode( 'entry-twitter-link' ); // Not exactly required
add_shortcode( 'entry-twitter-link', 'my_remove_shortcode' );
}
add_action( 'init', 'shortcode_cleaner' );
function my_remove_shortcode(){
return '';
}
4
I would hook into the wp_head action. I would place this in a plugin so as to abstract it from your presentation layer. This allows for scalability and changing of themes. This also prevents any analytics collateral damage if a step is missed in migration from one theme to the next.
add_action('wp_head', 'wpse_43672_wp_head');
function wpse_43672_wp_head(){
...
4
A plugin never edits those files - WordPress uses a system of "hooks" and "filters" that allows plugins to change behaviour without altering code.
So, in short, as long as you've created your child theme correctly, plugins will work fine.
Some references:
http://codex.wordpress.org/Child_Themes
http://codex.wordpress.org/Plugin_API
4
It might look more elegant, but you don't want to nest hooks in this way. You're now ending up with actions added inside a logic check inside another action hook.
Instead, keep your functions as granular and atomic as possible and only hook them in where needed. Your first technique isn't inefficient at all, it's the way you should be doing things.
One ...
Only top voted, non community-wiki answers of a minimum length are eligible