It is all started after I updated some of the plugins in my Wordpress site.

Right now I'm getting an Http Internal 500 Error when I try to access WordPress dashboard.

Error at my error log file in File Manager.

PHP Fatal error:  Call to a member function locale() on a non-object in /wp-content/themes/my_theme/lib/custom.php at line 25.

my custom.php file looks like this.

24. global $sitepress;
25. setlocale(LC_TIME, $sitepress->locale() . '.UTF-8');
26. $_SESSION['date_format'] = (ICL_LANGUAGE_CODE == 'fr') ? 'le %e %B %G' : '%B %e, %G';

Any suggestions on this issue!!

  • 1
    clearly $sitepress isn't an object as expected, can you find out what $sitepress actually contains and its data type?
    – Tom J Nowell
    Aug 10, 2017 at 15:37

2 Answers 2


$sitepress is a global set by WPML, IIRC. Change your line 25 as follows:

if(isset($sitepress) && is_object($sitepress)) {
  setlocale(LC_TIME, $sitepress->locale() . '.UTF-8');

As a general rule you shouldn't assume in a theme that anything included in or set by a plugin will be available, because it's possible to disable the plugin while the theme is still active. Always include some sort of sanity check before attempting to access a variable, class or function from a plugin in your theme.

Edit: based on your discovery that the method you used has been deprecated, I'd suggest the following for your updated file:

if(isset($sitepress) && method_exists($sitepress, 'get_locale')) {
  setlocale(LC_TIME, $sitepress->get_locale(ICL_LANGUAGE_CODE) . '.UTF-8');

This fixed the problem!

$sitepress->locale() function was no longer available in new version of the wpml plugin. So a new update of WPML plugin broke the translation function.

global $sitepress;
setlocale(LC_TIME, $sitepress->get_locale(ICL_LANGUAGE_CODE) . '.UTF-8');
$_SESSION['date_format'] = (ICL_LANGUAGE_CODE == 'fr') ? 'le %e %B %G' : '%B %e, %G';
  • You should still check if $sitepress is available before using it for the reasons I outlined above.
    – Chris Cox
    Aug 11, 2017 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.