我有这个多语种网站。有没有办法在切换到"中文后可以将logo.png更改为不同的.png?"
我现在正在使用polylang插件,这就是我一起拼凑的:
$(function() {
if (pll_current_language == 'en') {
$('.logo').css("background-image", "url(images/logo.png)");
} else if (pll_current_language == 'zh') {
$('.logo').css("background-image", "url(images/logo-CN.png)");
} else {
$('.logo').css("background-image", "url(images/logo.png)");
}
});
答案 0 :(得分:0)
更改
if (pll_current_language == 'en') {
$('.logo').css("background-image", "url(images/logo.png)");
} else if (pll_current_language == 'zh') {
$('.logo').css("background-image", "url(images/logo-CN.png)");
} else {
$('.logo').css("background-image", "url(images/logo.png)");
}
到
if (pll_current_language() == 'en') {
$('.logo').css("background-image", "url(images/logo.png)");
} else if (pll_current_language() == 'zh') {
$('.logo').css("background-image", "url(images/logo-CN.png)");
} else {
$('.logo').css("background-image", "url(images/logo.png)");
}
应该有用,你错过了"()"在" pll_current_language"
之后编辑:试试这个:
$( document ).ready(function() {
<?php
if (pll_current_language() == 'en') {
?>
$('.logo').css("background-image", "url(images/logo.png)");
<?php
} else if (pll_current_language() == 'zh') {
?>
$('.logo').css("background-image", "url(images/logo-CN.png)");
<?php
} else {
?>
$('.logo').css("background-image", "url(images/logo.png)");
<?php
}
?>
});