最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

child theme - Undefined functions on the server

programmeradmin2浏览0评论

Probably a silly one but hopefully someone has encountered this before.

The problem:

I have a local copy of my Wordpress site that works fine and a copy on the server. After uploading I get Call to undefined function from within the child theme's header.php referencing a function that should exist in its parent theme.

Full error message:

Fatal error: Call to undefined function shapely_get_header_logo() in /home/twimp/training.twimp.co.uk/wp-content/themes/shapely-child/header.php on line 33

Background:

The server has recently had a Wordpress site running on it fine so I don't have particular reason to think its anything related to its configuration.

I'm using a different theme from the last time it was uploaded so I started by uploading these two directories, my child theme and its parent. A lot of changes had been made with the plugins so I cleared the plugins directory and re-uploaded everything.

I also completely wiped the database and imported from local and then modified the options table to put the correct server url back in.

wp_config has not been touched and so it still points at the right database.

What I've tried:

I initially thought that maybe a file or two hadn't uploaded so I checked the FTP server side by side, starting with the files it should have been looking at. They all seem to be there.

I thought perhaps it was a file permission problem so I reset all of the files in the wp_content directory.

Just in case I was losing my mind, I have tried making small changes to the header.php just to confirm it is in fact the right file on the right server and the database is looking at the right files. All normal.

I tried commenting out the erroneous function call but all that did was move the error down to the next function called.

I checked the style.css to check its parent declaration was correct. I noticed there is a difference in file size between server and local but I've downloaded the file and it looks correct.

I modified the functions.php on both parent and child simply to var_dump the current user. The child theme printed, the parent theme did not.

Conclusion: It seems as if my child theme is not aware of its parent when on the server but I can't figure out why that might be.

Child theme style.css

/*
Theme Name: Shapely Child
Template: Shapely
Version: 1.1.7
Author: colorlib
Author URI: LINK
*/

Parent theme style.css

/*
Theme Name: Shapely
Theme URI: LINK
Author: colorlib
Author URI: LINK
...
*/

I apologise in advance if I've skipped over anything essential.

Any and all help is greatly appreciated.

Probably a silly one but hopefully someone has encountered this before.

The problem:

I have a local copy of my Wordpress site that works fine and a copy on the server. After uploading I get Call to undefined function from within the child theme's header.php referencing a function that should exist in its parent theme.

Full error message:

Fatal error: Call to undefined function shapely_get_header_logo() in /home/twimp/training.twimp.co.uk/wp-content/themes/shapely-child/header.php on line 33

Background:

The server has recently had a Wordpress site running on it fine so I don't have particular reason to think its anything related to its configuration.

I'm using a different theme from the last time it was uploaded so I started by uploading these two directories, my child theme and its parent. A lot of changes had been made with the plugins so I cleared the plugins directory and re-uploaded everything.

I also completely wiped the database and imported from local and then modified the options table to put the correct server url back in.

wp_config has not been touched and so it still points at the right database.

What I've tried:

I initially thought that maybe a file or two hadn't uploaded so I checked the FTP server side by side, starting with the files it should have been looking at. They all seem to be there.

I thought perhaps it was a file permission problem so I reset all of the files in the wp_content directory.

Just in case I was losing my mind, I have tried making small changes to the header.php just to confirm it is in fact the right file on the right server and the database is looking at the right files. All normal.

I tried commenting out the erroneous function call but all that did was move the error down to the next function called.

I checked the style.css to check its parent declaration was correct. I noticed there is a difference in file size between server and local but I've downloaded the file and it looks correct.

I modified the functions.php on both parent and child simply to var_dump the current user. The child theme printed, the parent theme did not.

Conclusion: It seems as if my child theme is not aware of its parent when on the server but I can't figure out why that might be.

Child theme style.css

/*
Theme Name: Shapely Child
Template: Shapely
Version: 1.1.7
Author: colorlib
Author URI: LINK
*/

Parent theme style.css

/*
Theme Name: Shapely
Theme URI: LINK
Author: colorlib
Author URI: LINK
...
*/

I apologise in advance if I've skipped over anything essential.

Any and all help is greatly appreciated.

Share Improve this question edited Aug 25, 2017 at 12:40 Ross Coombes asked Aug 25, 2017 at 9:37 Ross CoombesRoss Coombes 114 bronze badges 10
  • What's the undefined function? – Jacob Peattie Commented Aug 25, 2017 at 9:52
  • Please share the theme name and function name which trigger the error. Maybe that function name is deprecated from parent theme. – maheshwaghmare Commented Aug 25, 2017 at 9:58
  • @maheshwaghmare Deprecation does not produce that error. – fuxia Commented Aug 25, 2017 at 10:00
  • The undefined function is "shapely_get_header_logo" from the shapely theme but I don't believe that's the issue because it just happens to be the first one in the header.php file that is called and if I comment it out, I just get the same error on the second. – Ross Coombes Commented Aug 25, 2017 at 10:14
  • @RossCoombes can you edit your question to contain the full error message? Also, please include the top of style.css so we can check everything needed to do a child theme has been put in place correctly – Tom J Nowell Commented Aug 25, 2017 at 11:04
 |  Show 5 more comments

3 Answers 3

Reset to default 0

Well... I fixed it finally.

I decided to bypass my child theme to try and allow myself to login to the admin system on the server. To do that I went into the database and set both the template and stylesheet options manually to "shapely". Once in, I used the interface to re-select my child theme and voila, my theme now works.

I looked at the source code for switching theme and the options it changes in the database are template, stylesheet, current_theme and theme_switched.

After a bit of trial and error, I was able to replicate the exact problem by changing the case of the template option. Unfortunately I may never know exactly where or how the discrepancy came about but thank you to @maheshwaghmare as you put me on the right track.

You need to use Template: shapely instead of Template: Shapely

E.g.

/*
Theme Name: Shapely Child
Template: shapely
Version: 1.1.7
Author: colorlib
Author URI: LINK
*/

Template is the directory/folder name on you're parent theme.

For more detail's about child theme @see https://codex.wordpress/Child_Themes#How_to_Create_a_Child_Theme

I have added this answer instead of cement to highlight and help it other's.

For others that end up here, it's important to firstly put the comments in the style.css file of the child theme and secondly to make sure to do it with the correct casings.

发布评论

评论列表(0)

  1. 暂无评论