在 WordPress 上调用 Javascript 响应式工具提示

Calling Javascript on Wordpress Responsive Tooltip

本文关键字:响应 工具提示 Javascript 调用 WordPress      更新时间:2023-09-26

所以我通读了Wordpress关于在特定页面中调用javascript的文章。

我只想在一页上输入,因为我只在该页面上使用脚本。

我用于工具提示的教程在这里:

http://osvaldas.info/elegant-css-and-jquery-tooltip-responsive-mobile-friendly

我想我错误地调用了脚本:

这是我在页面上使用的代码:

<script type="text/javascript" src="http://www.frgraphicsolutions.com/working/wp-content/themes/responsive-child/tooltip.js"></script>
<abbr title="We provide companies with advice and best practices on how to promote and     advance your graphic marketing projects. Our consultative approach analyzes your current practices and offers ideas on how to lower your costs and increase the effectiveness of your (limited) marketing budget." rel="tooltip"><img style="vertical-align: middle;" alt="" src="http://frgraphicsolutions.com/wp-content/uploads/2013/06/001.png" /></abbr> 
<abbr style:"float: right" title="We offer turn-key programs for small and medium-sized business to build your brand and establish an online presence, including the development of web pages, social media and lead-generation email campaigns. Services include graphic design and copywriting." rel="tooltip"><img style="vertical-align: middle;" alt="" src="http://frgraphicsolutions.com/wp-content/uploads/2013/06/002.png" /></abbr>

它不起作用,我仍然对如何在wordpress上调用javascript感到非常困惑。

有人可以澄清一下吗?

非常感谢。:)

好的,

这是我通过一些严肃的互联网搜索和wordpress论坛的帮助找到的解决方案:

1.对Javascript进行更改,使其没有冲突(如Ivan Hanak所说)

第一行变成这样:

jQuery( document ).ready( function($)

参考:

  • jQuery noConflict Wrappers

    2.在我的 cild 主题中制作一个函数.php文件

    我想确保该功能仅适用于我网站的一个页面,这样它就不会降低我的网站性能

所以该文件的 php 如下所示:

<?php
if ( !function_exists( 'tool_tips' ) ) {
function tooltips() {
if ( is_page( 'Services' ) ) {
wp_enqueue_script( 'tooltips', get_stylesheet_directory_uri() . '/js/tooltips.js', '', '1.0', true );
   }
  }
}
add_action( 'wp_enqueue_scripts', 'tooltips' );
?>

is_page

函数让我调用我希望 Java 加载的任何特定页面。

参考资料(关于 Wordpress.org 法典):

  • 函数引用/wp 排队脚本
  • 函数引用/是页面
  • 子主题

感谢您的所有帮助,这需要很多挖掘,但现在我有一个功能更好的网站!

我查了你的网站,我发现了一个问题,为什么它可能不起作用。您需要编辑脚本以使用 jQuery 无冲突语法。

打开工具提示.js

和第一行

$( document ).ready( function()

换成

jQuery( document ).ready( function($)

这种"情况"被描述为jQuery noConflict Wrappers

我仍然对如何在WordPress上调用JavaScript感到非常困惑。

为此,请使用Google,WordPress文章在这里enqueueing a script