What makes a Wordpress theme an "invalid parent theme"? - wordpress

In order to overwrite some CSS of an existing Wordpress theme, I would like to create a child theme of it as described on http://codex.wordpress.org/Child_Themes#Example_of_a_basic_Child_Theme .
I created a directory along with the style.css file, where the parent theme's name is defined as "template". So far, so good. When I go to the themes page in Wordpress' administration, I get the message "The [name of parent theme] theme is not a valid parent theme.", and I cannot activate it.
I am wondering how Wordpress finds out if a parent theme is valid or not and if there is a way to make the parent theme a valid parent theme.
In order to find out if the defined parent theme is the problem, I replaced the "template" definition with another theme, which is also installed on the same server, and that worked.
Thanks in advance for your help.

It seems I forgot to mention the fact that caused the problem: My parent theme is already a child theme, and I was not aware of the two generation limit, which means that a child child theme is not possible. :-(
Thanks for your help anyway! Maybe this information should be added on http://codex.wordpress.org/Child_Themes ...

try checking your child theme's css and look at the #import line and make sure there is a ';' semicolon at the end. :)

Your child theme needs to use exactly the same name (same cases, same spaces etc.) as the parent theme. It's defined as Theme Name in the parent's style.css.

Related

Child Theme Index.php won't override parent theme

So I've built several sites like this, using a child theme to be able to customize what I want.
This time, I have a child theme directory with a style.css and functions.php, etc.
The style sheet overrides fine, even the header.php I added overrides. However, index.php will not override the parent theme's index.php.
Anyone have any ideas?
It sounds like you've set everything up correctly, from the fact that your header.php is overriding the parent theme.
The index.php template is the final fallback if Wordpress cannot find a more appropriate template to use. Most likely, it's selecting another template from the parent theme - eg. archive.php, frontpage.php, home.php, single.php - or many others depending on which particular URL you are viewing.
This visual overview of Wordpress' template hierarchy will help you understand how it works. Using this, you should be able to locate which template file is being selected in the parent theme and therefore, which one you need to override.

Hiding Wordpress parent theme

I am using the child theme and have renamed it to the new theme name. However, the parent theme is still viewable in the admin area with the original theme name. How do I hide the parent theme? Thanks.
As far as I know this cannot be done. The idea behind child themes is to be Update Safe.
This means, you can update the parent theme and all the child theme functionality goes unaffected. If you want to hide the parent theme, you are better off forking it.
As i seen on wp-admin/themes.php file that wordpress use function called wp_prepare_attachment_for_js to collect the available theme information and then display it on themes page.
The function wp_prepare_attachment_for_js located on wp-admin/theme.php may be line 409 and seems the function have filter wp_prepare_attachment_for_js, so i think this will be done with this filter by unset the selected theme (parent theme to hide) before displayed to the available themes.
try add filter like this to your functions.php
add_filter( 'wp_prepare_themes_for_js', 'test_hide_themes', 11, 1 );
function test_hide_themes($prepared_themes){
// hide parent-theme theme
unset($prepared_themes['your-parent-theme-slug']);
return $prepared_themes;
}

Require another file before require file functions.php Wordpress

Same as title, i want require file 'foo.php' before wordpress require 'functions.php' in theme. What's solution? Somebody can help me?
Use a Child Theme.
Basically you just do this:
Create a directory in your themes directory to hold the child theme.
The theme directory is wp-content/themes. You should name the
directory without any space as part of the name, and it is common
practice to use the name of the parent theme folder with “-child”
appended to it. For example, if you are making a child of the
twentyfourteen theme, your folder name would be twentyfourteen-child.
Inside, you can create a functions.php and add the code you want, you can even call other files, like your foo.php:
(...) 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.)
You can also create a plugin, they are loaded before functions.php, you can take a look at the loading order here: https://wordpress.stackexchange.com/questions/26537/between-functions-php-widgets-and-plugins-which-is-loaded-first

can we add add_action('admin_init','myfunction') in wp-includes/functions.php

I have a question regarding add_action, can i able to add add_action in functions.php that is wp-includes/functions.php
add_action('admin_init','myfunction');
You can, but you should not since all your modifications will be overwritten when you upgrade wordpress. Use your theme's functions.php instead.
Don't put it in wp-includes for the reasons rrikesh states. You're just going to the code on update.
If you have a lot of themes within which you want common functionality, make them children of a parent theme.
The parent can hold all the common code in its own functions.php file and the children will be able to use it.
Review the codex for information on Child Themes and how to implement them.

Wordpress, Gantry Framework, Child Theme?

Does anyone have experience with Gantry Framework?
I am wondering if it is possible to create a child theme based off of the default? Where would I put my css file and can I build off of the current css instead of starting from scratch while still separating my css from the default theme?
Apart from the usual process of creating a WordPress child theme (create a directory, with proper style.css and functions.php), Gantry requires a specific procedure.
You'll need to copy two files from the parent directory to the child theme directory, keeping the structure:
/gantry/theme.yaml
and
/includes/theme.php
Then, edit the copied theme.yaml: the parent must be your parent theme directory name.
On the theme.php, select all text and replace with this:
// Initialize theme stream.
$gantry['platform']->set(
'streams.gantry-theme.prefixes',
array('' => array(
"gantry-themes://{$gantry['theme.name']}/custom",
"gantry-themes://{$gantry['theme.name']}",
"gantry-themes://{$gantry['theme.name']}/common",
"gantry-themes://{$gantry['theme.parent']}",
"gantry-themes://{$gantry['theme.parent']}/common"
))
);
As for css, you must create this file, within your child theme directory:
/custom/scss/custom.scss
It can be formatted in either SCSS or CSS, and will override the theme's core style sheet files.
Creating a Child Theme is very easy.
All you need to do is create a directory in your theme directory, and name it something like "Gantry-child". Inside that folder, add a file called "style.css". Once this is done, you just need to add the Theme Information that tells Wordpress the Child Theme's Name, Author, and Parent Theme.
Inside the new style.css, add:
/*
Theme Name: Gantry Child
Template: rt_gantry_wp
*/
The most important part that lets Wordpress know that this is a child of the Gantry Theme is the "Template" section. This is the name of the PARENT directory in your Themes folder.
What this will do is create a new theme that inherits all of the parent theme's functions. If you also want to inherit the existing parent theme stylesheet, add to style.css:
#import url("../rt_gantry_wp/style.css");
Hopefully this should get you started. Once that's done, you can add your own header, footer, index, functions, or anything else you can think of to extend the parent theme's functionality.
Hopefully this helps get you started.

Resources