customizer-polylang icon indicating copy to clipboard operation
customizer-polylang copied to clipboard

Language switcher is missing.

Open richardevcom opened this issue 5 years ago • 2 comments

After including the file like this in main theme (i'm not using child theme) functions file like this (i'm using predefined constants with full directory addresses): require_once(PN_LIBRARIES_DIR . '/customizer-polylang/customizer-polylang.php'); the language switcher is missing.

[UPDATE] In Console i get this error:

Loading failed for the <script> with source “http://localhost/project/back-end/wp-content/themes/project/js/customizer-polylang.js?ver=1438771592”. customize.php:1602:1
ReferenceError: PSPolyLang is not defined

If I change 246 line in customizer-polylang.php to also use constant with full directory URL like so: $src = PN_LIBRARIES_URL . '/customizer-polylang/js/customizer-polylang.js'; Then I get it working.

Is this issue because I'm using it in main theme and not in child theme?

richardevcom avatar Jan 29 '20 09:01 richardevcom

No, it should work for both main and child themes. I'll look into it (thought I'd fixed this, have to compare the code here with the one I use in production)

soderlind avatar Jan 29 '20 11:01 soderlind

Well, just in case the full adrresses for DIRs and URLs I've predefined look like this:

// Directory addresses
define("PN_BASE_DIR", dirname(dirname(__FILE__)));
define("PN_INCLUDES_DIR", PN_BASE_DIR . '/includes');
define("PN_LIBRARIES_DIR", PN_BASE_DIR . '/libraries');
define("PN_ASSETS_DIR", PN_BASE_DIR . '/assets');
define("PN_LANGUAGE_DIR", PN_BASE_DIR . '/languages');
define("PN_TEMPLATES_DIR", PN_BASE_DIR . '/templates');

// URL addresses
define("PN_BASE_URL", get_stylesheet_directory_uri());
define("PN_INCLUDES_URL", PN_BASE_URL . '/includes');
define("PN_LIBRARIES_URL", PN_BASE_URL . '/libraries');
define("PN_ASSETS_URL", PN_BASE_URL . '/assets');
define("PN_LANGUAGE_URL", PN_BASE_URL . '/languages');
define("PN_TEMPLATES_URL", PN_BASE_URL . '/templates');

And the final output, looks like this (i double checked and I think it's something to do with using main theme and not child theme:

string(80) "C:\Users\user\Projects\project\back-end\wp-content\themes\project/libraries"
string(69) "http://localhost/project/back-end/wp-content/themes/project/libraries"

So.. in the functions.php I call your library like this: require_once(PN_LIBRARIES_DIR . '/customizer-polylang/customizer-polylang.php'); and changed 246 line in customizer-polylang.php to this: $src = PN_LIBRARIES_URL . '/customizer-polylang/js/customizer-polylang.js';

And thanks for free solution. Really appreciate it.

richardevcom avatar Jan 29 '20 14:01 richardevcom