Wordpress从http://更改网址到tel: [英] Wordpress change url from http:// to tel:

查看:127
本文介绍了Wordpress从http://更改网址到tel:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我整天都被困在这一天!

I've been stuck on this all day!

我在Wordpress中使用自定义wp_nav,我需要从href =更改一个自定义菜单项http://555.555.5555to href =tel:555.555.5555。我在菜单项中添加了一个class =phone,我想使用该类更改它(因为我无法在WP中添加自定义ID)。

I'm using a custom wp_nav in Wordpress and I need to change one custom menu item from href="http://555.555.5555" to href="tel:555.555.5555". I've added a class="phone" to the menu-item and I'd like to change it using that class (since I can't add a custom id in WP).

我更喜欢它在onLoad而不是onClick上完成。非常感谢您的帮助。

I'd prefer it be done onLoad and not onClick. Your help is much appreciated.

Wordpress输出的代码是:

The code output by Wordpress is:

<li id="menu-item-654" class="phone menu-item menu-item-type-custom menu-item-object-custom menu-item-654"><a href="http://555.555.5555">Call</a></li>

我需要使用Javascript看起来像这样:

I need it to look like this using Javascript:

<li id="menu-item-654" class="phone menu-item menu-item-type-custom menu-item-object-custom menu-item-654"><a href="tel:555.555.5555">Call</a></li>


推荐答案

当然你对一个小jQuery感到满意,加载在WordPress中将其粘贴到标题中,或者为 wp_head 创建 add_action

Granted you're comfortable with a little jQuery, load it up in WordPress and paste this into your header, or create an add_action for wp_head.

<script type="text/javascript">
jQuery(document).ready(function(){

  var href_value;

  href_value = jQuery('li.phone a').attr('href');

  href_value = href_value.replace('http://','tel:');

  jQuery('li.phone a').attr('href',href_value);

});
</script>

请告诉我这是否适合您。

Let me know if that worked for you.

这篇关于Wordpress从http://更改网址到tel:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆