Wordpress child theme not loading modified template PHP files inside subfolders - wordpress

I'm starting learning Wordpress development, and I'm stuck trying to create a child theme. Below I enumerate the steps I followed to see if someone can help me:
Create a folder under 'wp-contents/themes' called 'shoptest'
Inside, I've created a file 'style.css' with the following content:
/* Theme Name: Shoptest
Theme URI: http://www.testsite.com
Description: Shop Isle child theme
Author: Felip
Template: shop-isle
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
Text Domain: shop-isle
*/
I created a file 'functions.php' with the following:
I've activated the theme in Wordpress dashboard
I've created a couple of folders 'inc/structure' and copied the file original 'inc/structure/footer.php' inside.
So:
The original file is: 'wp-content/themes/shop-isle/inc/structure/footer.php'
The child file is: 'wp-content/themes/shoptest/inc/structure/footer.php'
In theory, if I change/add something in the child file, the webpage should reflect that change, right? I've tried but it does nothing. Just for testing, if I change anything on the original footer.php file, it's immediately changed in the website.
What am I doing wrong?

Wordpress doesn't work this way as you think.
You should write your changes as a function and put it in functions.php of your child theme.
Then use the wp_footer hook to hook your changes to the footer.
like below
function my_custom_changes() {
// add your code
}
add_action('wp_footer', 'my_custom_changes' );

Related

Can I change the theme name in WordPress?

How can I change the theme name in WordPress and where?
Can I also change the folder name theme1244 in public/wp-content/themes/theme1244 without having problems in the future?
Step 1: Firstly go to wp-content/themes/ folder. And then rename your theme folder to whatever you want.
Step 2: Open your theme folder and open style.css file. In top part of style.css you will see theme name. Rename it and save changes.
Step 3: Go to Wp-admin/appearance/themes and activate your theme under new name.
If you are using child/parent theme and you also rename parent theme folder&name, so after Step 3 you should additionally change parent theme path (template field) in child theme’s style.css.
note : renaming your theme will stop its automatic updates, you should do it manually in the future.
All the above is correct, but is not enough. After you rename the theme, e.g. rename the folder old-theme --> new-theme, you should copy the theme customizations (colors, header / footer, widgets, etc.) from the old theme to the new theme. This is done directly in the MySQL database:
Find an option named theme_mods_old-theme in the table wp_options
Copy the option_value (it is a text holding the theme customizations in a special WordPress format)
Put the copied value in a new option named theme_mods_new-theme in the wp_options table.
You can absolutely change the name of the folder without having any problems. If you want to change just the themes name, open the style.css in the root folder of your theme and edit the name in the comments at the top of the file. If you plan on doing more changes, you might be better off creating a child theme: https://codex.wordpress.org/Child_Themes
I changed my theme name in wp-content/themes/{your site name folder}/style.css
I am using a child theme
/*
Theme Name: WhateverYouWantToNameIT
Template: twentytwenty
*/
The answers above are good, but I wanted the full list and this is it
so go to: wp-content/themes/{your site name folder}/style.css
and change this values if they exist, if not you can add them
/* this should be at the top of your theme CSS file
Theme Name: Twenty Fifteen Child
Theme URI: http://example.com/twenty-fifteen-child/
Description: Twenty Fifteen Child Theme
Author: John Doe
Author URI: http://example.com
Template: twentyfifteen
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
Text Domain: twentyfifteenchild
*/
See Source for more details
Its absolutely easy and simple, just follow instruction
1. Just rename theme name with your desire theme name.
2. open your desire theme name and open style.css file, and find theme name and changes with your desire theme name.
3. you can see your desire theme in admin dashboard-> appearance-> themes, just select and activate it.

Wordpress child theme white screen

Not sure what I'm doing wrong here. I started out with an ordinary custom theme and then decided to extend the twentyfifteen theme instead so I brought in the parent theme's style per the codex, and added the Template to my style.css file.
I had some custom stuff in functions.php, but even if I delete all of it except the wp_enque_style, I still get the white screen.
I have debug turned on. There aren't any errors at all. Just a white screen.
Here's my functions file:
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'twentyfifteen-style', get_template_directory_uri() . '/style.css' );
}
And my Style.css
/*
Theme Name: veochild
Theme URI:
Template: twentyfifteen
Author: veo
Author URI:
Description: Veo Child Theme
Version: 1.0
License:
License URI:
Tags:
Text Domain: veo
*/
Oddly enough, If I type in domain.local/wp-admin I am still able to access the admin site. If I change the theme to twentyfifteen it works fine. I don't have any other files in my theme directory other than functions.php and style.css and my theme folder is in the same directory as twentyfifteen.
Not really sure what else to look for.
Oddly enough, when I said:
I don't have any other files in my theme directory other than functions.php and style.css
...I lied or I must have been blind. What was also in that folder was an empty index.php file.
It took me a while before realizing that. Thanks for anyone who looked at this. Sorry for the waste of time.

How to activate the child theme in Wordpress?

I create a new style.css and use it in child theme. And I create a new folder in wp-content and name it as themename-child and upload the style.css that I created. Now, I go to wp dashboard -> Appearance -> Themes and I look the child theme that I create. And I found this error:
Broken Themes
The following themes are installed but incomplete. Themes must have a stylesheet and a template.
Name Description
Accesspress Lite The parent theme is missing. Please install the "AccesspressLite" parent theme.
Is there anything that I need to upload? Please help me. I'm new in WordPress. Thank you!
No, the problem here is that you must specify the parent template in commented area of your child style.css
Example from Wordpress Codex
/*
Theme Name: Twenty Fourteen Child
Theme URI: http://example.com/twenty-fourteen-child/
Description: Twenty Fourteen Child Theme
Author: John Doe
Author URI: http://example.com
Template: twentyfourteen
Version: 1.0.0
Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
Text Domain: twenty-fourteen-child
*/
#import url("../twentyfourteen/style.css");
Line with
Template: twentyfourteen
is what your need. Your parent theme must be in corresponding folder, in this example, themes/twentyfourteen.
Also, in your parent template you must load style.css via get_stylesheet_uri() for child theme to work correctly.
Seems clear to me that you need to install the Parent Theme, which is required for child theme installation...
The parent theme is missing. Please install the "AccesspressLite" parent theme.
The whole purpose of the child theme is that it feeds it's adjustments into the parent theme, so you don't have to adjust parent theme settings.

How to create child theme?

I have enfold theme installed in my Wordpress site. i have tried following things
1)i have create one folder named - enfold-child
2)i have create two files in that folder
1) style.css
2) functions.php
3)screenshot of parent theme enfold
now i have placed code in style.css like this
/*
Theme Name: Enfold
Description: <strong>A superflexible and responsive Business Theme by Kriesi</strong> - <br/> Update notifications available on twitter and facebook:<br/> <a href='http://twitter.com/kriesi'>Follow me on twitter</a><br/> - <a href='http://www.facebook.com/pages/Kriesi/333648177216'>Join the Facebook Group</a>
Version: 2.2
Author: Kriesi
Author URI: http://www.kriesi.at
License: Themeforest Split Licence
License URI: -
Theme URI: www.kriesi.at/themes/enfold/
Template: enfold
*/
but when i am open themes in admin panel this message displays in enfold child - This child theme requires its parent theme, Enfold.
so where does i mistaken
my enfold parent theme has code like this
- /*
Theme Name: Enfold
Description: <strong>A superflexible and responsive Business Theme by Kriesi</strong> - <br/> Update notifications available on twitter and facebook:<br/> <a href='http://twitter.com/kriesi'>Follow me on twitter</a><br/> - <a href='http://www.facebook.com/pages/Kriesi/333648177216'>Join the Facebook Group</a>
Version: 2.2
Author: Kriesi
Author URI: http://www.kriesi.at
License: Themeforest Split Licence
License URI: -
Theme URI: www.kriesi.at/themes/enfold/
*/
/*
* PLEASE DO NOT EDIT THIS FILE!
*
* This file is only in your themefolder for WordPress to recognize basic theme data like name and version
* CSS Rules in this file will not be used by the theme.
* Instead use the custom.css file that is located in your themes /css/ folder to add your styles.
* You can copy a style rule from any of your css files and paste it in custom.css and
* it will override the original style. If you just want to add small css snippets you might also
* want to consider to add it to the designated CSS option field in your themes backend at: Theme Options->Styling
*/
Please help
you need not to do anything, you can download ready made enfold child theme.. just copy following link and paste into your browser's address bar...
https://kriesi.at/files/enfold-child.zip
if you want to create custom one, then check following link.
https://vimeo.com/67221517
I hope you will like it.. :)
You need to add code in style.css of child theme like as follows
/*
Theme Name: your child theme name
Theme URI: http://example.com/child-theme-url/
Description: your Child Theme desc
Author: your author name
Author URI: http://example.com
Template: enfold
Version: 1.0.0
*/
/* =Imports styles from the parent theme
-------------------------------------------------------------- */
#import url('../enfold/style.css');
Template : is the your parent theme folder name.
I hope this will help to resolve your problem.
You need to include Template: enfold in style.css of your child theme.
See this official wordpress docs link of Child theme http://codex.wordpress.org/Child_Themes & read especially this part:
....You can change each of these lines to suit your theme. The only
required lines are the Theme Name, and the Template. The Template is
the directory name of the parent theme. In this case, the parent theme
is the TwentyThirteen theme, so the Template is twentythirteen, which
is the name of the directory where the TwentyThirteen theme resides....

Template Dropdown not showing up within Wordpress administrator page

I am working on a Wordpress-based project, and I just added a new template to the installation by uploading a template file. I was creating a new page that will use my new template, when suddenly, the "Template" dropdown in the "Page Attributes" box is gone.
I am using Wordpress 3.0.1.
Update:
I saw a site which told me to revert to the default template, and back to my custom template. Apparently it worked, but I am still baffled on what triggers this bug. Also, any additional knowledge or pointers on this bug would be a great help since my job requires me to patch this (and possibly submit the bug fix to Wordpress). Thanks!
If you have disabled or removed the style.css from the template directory then also it will not work.
So there must be the style.css on template directory then the templates directory will be shown. When you try to remove the style.css from the template directory or using style.css from css folder, then you must be put one style.css on template directory.
Thanks
Morichika is spot on. I had the same problem, but then it sorted itself out by doing:
<?php
/**
* Template Name: Front Page
*/
?>
I have found a different solution for this. I reactivated my custom theme but then problem persisted.. then in the top most section of the code for the custom page template where it actually defines the name of the template like this:
<?php
/*
Template Name: Front Page
*/
?>
I did this:
<?php
/**
* Template Name: Front Page
*/
?>
Then refreshed the admin panel and it appeared.Seems a bit weird but it worked for me. Feel happy to share this.
I tried many of the suggested answers. None worked in my case.
A possible reason for the Template Dropdown not showing is a missing index.php in your Theme folder.
Just create an empty one, in case your hierarchy does not need one. But the existance of that file enables the option to choose the page template and suppresses an error message in the Choose-Theme page btw
Put style.css in your theme directory, instead of the css folder. Or
<?php
/*
Template Name: Front Page
*/
?>
There must not space between "Template Name:".
I managed to fix this by making sure the style.css in the theme root contained the theme comments. I deleted the whole stylesheet and it removed the templates dropdown.
Put this at the top of your theme root's style.css.
/wp-content/themes/YOUR_THEME/style.css
/*
Theme Name: Twenty Thirteen
Theme URI: http://wordpress.org/themes/twentythirteen
Author: the WordPress team
Author URI: http://wordpress.org/
Description: The 2013 theme for WordPress takes us back to the blog, featuring a full range of post formats, each displayed beautifully in their own unique way. Design details abound, starting with a vibrant color scheme and matching header images, beautiful typography and icons, and a flexible layout that looks great on any device, big or small.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: black, brown, orange, tan, white, yellow, light, one-column, two-columns, right-sidebar, flexible-width, custom-header, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, translation-ready
Text Domain: twentythirteen
This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned with others.
*/
https://codex.wordpress.org/Theme_Development#Theme_Stylesheet
Or if you have a custom theme...
/*
Theme Name: My Wordpress Theme
Theme URI: https://example.tk
Author: Me
Author URI: https://example.tk
Description: This is my custom theme
Version: 1.0
*/
I know is super late for this question, but I fix it adding
Version: 0.1 alpha
in the comments of the themeFolder/style.css
This is my style.css complete for my theme
/*
Theme Name: Stockout Theme
Theme URI: http://stockout.com.uy/myTheme
Author: MauriPastorini
Author URI: http://stockout.com.uy
Description: This is a theme for stockout page
Version: 0.1 alpha
*/
I hope someone find this useful
I had the exact same problem with WordPress 3.2.1. I added a new template and the menu disappeared from the page add/edit screen. The solution was to switch back to the default twentyeleven theme end then right back to my custom theme. The templates drop-down began appearing again.
BTW, you said "revert to the default template, and back to my custom template" but I'm pretty sure you meant theme. I'm guessing where you saw this was here:
http://wordpress.org/support/topic/template-file-drop-down-not-appearing
Looks like this bug has existed for a couple of years at least. I filed a report:
http://core.trac.wordpress.org/ticket/18324
Try this. template will be available for both page & post
<?php
/**
* Template Name: Blog Post
* Template Post Type: post, page
?>
In WordPress 5.8 they have moved the selectable custom templates out from under the Page Attributes section so no matter what you do you won't find it there (even if you spend 2hrs troubleshooting like I did, lol).
Custom selectable templates have now been moved into their own box call "Template". For me, it was at the top of my right-hand sidebar in the WP admin page editor. It's possible it may not show if it has been unchecked in your screen options settings which are now found under the three dots in top-right --> Preferences --> Panels --> Ensure "Templates" is checked.
I'm not sure if I just overlooked it for 2hrs straight or if it appeared only after I changed to a different theme then changed back.
I had this problem a while back and found one janky solution after a lot of search--sometimes switching to another theme in your install and then switching back to you primary theme will make your templates appear. I know that sounds weird, but worked for me for a while.
I've had this problem for two days. This forum and a couple of tests later did the work. Here is what was missing for my part.
Be sure that there is a style.css in your theme folder.
The style.css must have a valid comment section at the top of the file.
This means at least this:
/*!
Template: your-theme
*/
If you're using SASS or LESS, make sure that you have a "!" just after declaring your comment. It's to prevent SASS or LESS to delete your comment section.
To be sure that everything is settled fine. You may go to "Appearance > Themes". After the listing of themes, if there is nothing, than everything should be fine. Otherwise, it'll be written "Broken Themes" and you'll still have some issues to solve.
sass had deleted the content in my child style.css. The template drop down shows again once I added back the comments.
/*
Theme Name: Sometheme Child
Description: Child theme for Sometheme.
Template: sometheme
Version: 1.1
Text Domain: sometheme-child
*/
You will not see the dropdown if you have added 0 custom template files in your theme root.
When at least 1 template is available, the WordPress ecosystem picks it up and the dropdown will become visible.
Add this in your theme root to try it.
<?php
/*
Template Name: Front Page
*/
The Template Dropdown is now moved To Page Section and is located just between the Static and Visibility and Permalinks dropdown. But you will be able to see it if you are naming your custom file like
page-Yourfilename.php
and adding a comment on the top of the file
<?php
/*
Template Name: YOUR TEMPLATE NAME
*/
?>
I was just facing the same issue so, the problem is in spacing between 'Template Name' and that colon.
/*
Template Name: template-name
*/
Make sure there is no spacing before the colon.
I found the root of the problem.
It is the style.css file inside the theme root.
It must be in "UNIX encoding".
It must have all comments with "Theme Name", "Version", etc.
Jack Nicholson was right! You need to make sure your style.css contains the full comment. Example below:
Previously mine was:
/*
Theme Name: Acadata
Theme URI: https://www.factorypattern.co.uk
Description: Custom
Author: Factory Pattern
Version: 1
License: GNU General Public License
License URI: license.txt
*/
Then I changed it to the below and now I can see all my templates.
/*
Theme Name: Acadata
Theme URI: https://factorypattern.co.uk/
Description: Custom
Author: Factory Pattern
Author URI: https://factorypattern.co.uk/
Description: The Acadata theme for WordPress.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: black, brown, orange, tan, white, yellow, light, one-column, two-columns, right-sidebar, flexible-width, custom-header, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, translation-ready
Text Domain: acadata
This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned with others.
*/
Please set properly you style.css file specially if you are working on child-theme
/*
Theme Name: Theme Name
Theme URI: http: //mysite.com/
Description: This is a custom child theme for xxx theme
Author: My Name
Author URI: http: //mysite.com/
Template: template_name_in_lowercase
Version: 0.1
*/
This below is work for me and show template option in page attributes.Just place .php file in theme root folder.
<?php
/* template name: my custom template */
?>
There are a lot of great answers on this question, but one obvious solution, which initially escaped me, was to double-check that in Dashboard > Settings > Reading you want to set "Your homepage displays" to "Static Page" and then leave the "Posts Page" unselected.
While themes and a properly coded theme file play a role in the situation, the reason that the page attributes area on the edit page screen doesn't show the templates drop-down may be because you selected a particular page to be your "Posts Page", and so WordPress is not asking you for a custom template to use because it's already using front-page.php or home.php (See WordPress Template Visual Hierarchy).
Hope this helps someone like me who had a properly coded template file but didn't realize this setting had been selected.
This was also a problem for me and it was because of folder structure. The Theme Handbook told me a should organize my theme folder and files like so:
assets (dir)
- css (dir)
- images (dir)
- js (dir)
inc (dir)
template-parts (dir)
- footer (dir)
- header (dir)
- navigation (dir)
- page (dir)
- post (dir)
404.php
archive.php
comments.php
footer.php
front-page.php
function.php
header.php
index.php
page.php
README.txt
rtl.css
screenshot.png
search.php
searchform.php
sidebar.php
single.php
style.php
The page template I was trying to load was in /template-parts/page/template-contactus.php
I guess that was too deep for WordPress so I got ride of those directories and now my file structure looks like this:
assets (dir)
- css (dir)
- images (dir)
- js (dir)
inc (dir)
template-parts (dir)
- section-content.php
- template-contactus.php
404.php
archive.php
comments.php
footer.php
front-page.php
function.php
header.php
index.php
page.php
README.txt
rtl.css
screenshot.png
search.php
searchform.php
sidebar.php
single.php
style.php
I am now able to see the template drop-down and add templates.
Hope this helps someone.
In my case, I had called the template schedule-template-v2.php which won't work, the file name needs to be schedulev2-template.php. A simple mistake.
In addition to all of the above, make sure that you have 'page attributes' checked in the screen options panel in the top right, otherwise the page attributes section wont show regardless.
If you are trying todo with blog page the GOTO Dashboard > settings > and remove post page from select menu :)
After searching I have found a stupid solution that was obvious because. Couldn't catch it because the templates were put in other place of interface attaching screenshot

Resources