wordpress主页上的自定义css和js
custom css and js on homepage in wordpress
我有我的html主页,标题如下。
<!--referring to CSS-->
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="css/animate.min.css">
<script type="text/javascript" src="http://updateyourbrowser.net/uyb.js"> </script> <!-- Update older browser -->
<!-- load the javascript library for the function in the script DOM-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<!--load the javascript library-->
<script src="js/external/jquery/jquery.js"></script>
<!--??what is this? we load the javascript library-->
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<!-- Google Analytics script -->
<script>//Google Analytics script
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-61904449-3', 'auto');
ga('send', 'pageview');
</script>
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','//connect.facebook.net/en_US/fbevents.js');
fbq('init', '384494271757075');
fbq('track', "PageView");</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=384494271757075&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
<script>
// Scrolling function for the top navigation
// ??top left? which navigation? => when you click to go back to the top, to make an ease effect
$(document).ready(function(){
$('a').click(function(){
$('html, body').animate({
scrollTop: $( $(this).attr('href') ).offset().top
}, {duration: 1500, easing: 'easeInOutExpo'});
return false;
});
});
<!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. -->
<script>var __adobewebfontsappname__="dreamweaver"</script>
<script src="http://use.edgefonts.net/source-sans-pro:i6,n6,n4,i4,i3,n3,n7,i7:default.js" type="text/javascript"></script>
我需要把它作为Wordpress主题的主页。我用以下方法把这个页面作为主题主页https://www.youtube.com/watch?v=ClXmWsE7wo8,我计划将此方法用于自定义css和Js如何将自定义css/js添加到WordPress中的一个页面?
但是我在定义自定义CSS和JS时遇到了问题。
在我的主页标题中,有1.从外部调用的css文件2.js从外部调用3.js定义的
我的第一个问题是,对于1和2,我如何定义wp_enque_script('your_script','path')中的路径;wp_enque_style("你的风格","路径");?
我应该做吗
wp_enqueue_style( 'main.css','/tstandtest/css/main.css' );
wp_enqueue_style( 'font-awesome.min.css','/tstandtest/font-awesome/css/font-awesome.min.css' );
wp_enqueue_style( 'jquery-ui.css','/tstandtest/font-awesome/css/font-awesome.min.css' );
wp_enqueue_style( 'font-awesome.min.css','//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css' );
我的第二个问题是,对于html标题中定义的js,我如何使其作为wordpress中的主页工作,例如谷歌分析脚本和Facebook像素脚本?
首先,如果您还没有获得主题资产的正确路径,则可能需要使用get_template_directory_uri()
:
// example
wp_enqueue_style('sage/css', get_template_directory_uri() . '/dist/styles/main.css', false, null);
你的第二个问题我不完全理解。如果你已经硬编码的ga和facebook脚本,它应该只是工作。然而,我会让this这样的插件管理插入最新的ga代码。
而且,我没有看你链接的视频教程,我想它提到你需要将<?php wp_head(); ?>
放在</head>
标签之前:https://codex.wordpress.org/Function_Reference/wp_head并且您已经从模板文件中删除了所有引用的样式表和外部脚本文件。
您可能还想关闭以开头的脚本块
<script>
// Scrolling function for the top navigation
// ??top left? which navigation? => when you click to go back to the top, to make an ease effect
$(document).ready(function(){
最后,我上次检查Wordpress时要求您指定jQuery对象的全名,因为它默认设置为"无冲突"模式。
为了帮助实现这一点,我使用了这个方便的闭包,传入完整的jQuery对象:
(function ($) {
// Now we can use $ within this closure
$(document).ready(UTIL.loadEvents);
})(jQuery);
- css/js:通过滚动固定位置
- 什么CSS/JS技巧驱动镜像反转http://com.google愚人节页面
- CSS/js Flip Cards
- 将回车键映射到HTML/CSS/JS中的按钮
- CSS/.JS问题,<ul><李>在Megamenu中
- 最小化CSS/JS文件,并使用命令行创建一个文件
- 使用公共JS文档优化静态网站的CSS/JS导入
- HTML/CSS/JS切换不同的谷歌日历是同一个框架
- 使用 PHP 将 css/js 文件分配给 html 文档
- HTML/CSS/JS 构建工具
- Knockout.js在标头中绑定css/js库
- 如何在HTML/CSS/JS中为表/列表应用行虚拟化
- 当包含在CSS/JS/HTML中时,我如何得出正确的目录路径
- 这段代码有什么问题(responsible html-css-js)
- CSS/JS:如何在悬停时显示文本,并显示点击href的文本框
- 如何使css/js对象在所有浏览器上都相同
- html+css+js组合在Google Chrome或Safari浏览器中无法正常工作
- CSS/JS转换:translate3d和滚动-在Android上流畅,在iPhone上没有动力
- 使用CSS/JS反转和重新反转元素
- 将复杂的html/css/js元素添加到单个Wordpress页面中