隐藏语言切换器名称

huangapple go评论59阅读模式
英文:

Hide language switcher names

问题

我试图隐藏语言切换器中的语言名称,只显示国旗。WPML支持告诉我,标准语言切换器由主题(Flatsome)提供,所以他们无法帮助。

Flatsome支持告诉我,他们无法帮助自定义解决方案。

我尝试通过“检查页面”自己找出负责这些语言名称的部分,但我发现影响了整个页眉-主要内容。没有找到仅负责“语言名称”的部分。

检查页面

所以我再次向WPML支持询问,我可以使用什么CSS或其他内容来隐藏这些名称,答案是:“function engage_header_langs()”。我不明白接下来该怎么做。

有人可以帮助吗?

英文:

I am trying to hide language names in the language switcher and show only flags. WPML support told me, that the standard language switcher is provided by the theme (Flatsome), so they couldn't help.

Flatsome support told me, that can't help with custom solutions.

I was trying to find by myself through the „inspect page“ what is responsible for those language names, but all i found were affected on the whole header-main content. Not found, what is responsible only for „language names“.

inspect page

So i asked WPML support again, what i can use for CSS or something to hide those names and the answer was: "function engage_header_langs()". And i do not understand what to do next.

Can anyone help with this?

答案1

得分: 0

以下是您要翻译的内容:

"The function you were given can likely be hooked into if you review your plugin's documentation. However, this can be done with some simple jQuery as shown in the snippet below. If you are using a custom JS file you can add this there (assuming you are already out of noConflict mode). If not, you can use the last snippet noted for your functions.php file. Update: I updated the script to adjust the css to display after it has removed the text. You will now need to add that to the functions.php file and the line of css above that to style.css (or wherever you are putting your css)

$(".has-dropdown.header-language-dropdown a").contents().filter(function() {
  return this.nodeType === 3;
}).remove();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
  <li class="has-dropdown header-language-dropdown">
    <a href="#">
      "Eesti"
      <i class="image-icon">
        <img src="https://cdn.pixabay.com/photo/2015/11/12/16/24/flag-1040595_960_720.png">
      </i>
    </a>
  </li>
</ul>

Add this to style.css

.has-dropdown.header-language-dropdown a {
    display:none;
}

//If adding to WordPress functions.php, use this block.
function add_script_to_head() {
    ?>
        <script>
            jQuery(document).ready(function($) {
                $(".has-dropdown.header-language-dropdown a").contents().filter(function() {
                    return this.nodeType === 3;
                }).remove().css('display', 'revert');
            });
        </script>
    <?php
}
add_action('wp_head', 'add_script_to_head');

"

英文:

The function you were given can likely be hooked into if you review your plugin's documentation.

However, this can be done with some simple jQuery as shown in the snippet below. If you are using a custom JS file you can add this there (assuming you are already out of noConflict mode). If not, you can use the last snippet noted for your functions.php file.

Update: I updated the script to adjust the css to display after it has removed the text. You will now need to add that to the functions.php file and the line of css above that to style.css (or wherever you are putting your css)

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

$(&quot;.has-dropdown.header-language-dropdown a&quot;).contents().filter(function() {
  return this.nodeType === 3;
}).remove();

<!-- language: lang-html -->

&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;ul&gt;
  &lt;li class=&quot;has-dropdown header-language-dropdown&quot;&gt;
    &lt;a href=&quot;#&quot;&gt;
      &quot;Eesti&quot;
      &lt;i class=&quot;image-icon&quot;&gt;
        &lt;img src=&quot;https://cdn.pixabay.com/photo/2015/11/12/16/24/flag-1040595_960_720.png&quot;&gt;
      &lt;/i&gt;
    &lt;/a&gt;
  &lt;/li&gt;
&lt;/ul&gt;

<!-- end snippet -->

//Add this to style.css
.has-dropdown.header-language-dropdown a {
    display:none;
}

//If adding to WordPress functions.php, use this block.
function add_script_to_head() {
    ?&gt;
        &lt;script&gt;
            jQuery(document).ready(function($) {
                $(&quot;.has-dropdown.header-language-dropdown a&quot;).contents().filter(function() {
                    return this.nodeType === 3;
                }).remove().css(&#39;display&#39;, &#39;revert&#39;);
            });
        &lt;/script&gt;
    &lt;?php
}
add_action(&#39;wp_head&#39;, &#39;add_script_to_head&#39;);

huangapple
  • 本文由 发表于 2023年2月16日 17:54:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75470521.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定