wordpress主题,修改头部代码加入JS

2024-12-18 17:20:01
推荐回答(2个)
回答1:

第一步:新建header.php

在做主题文件夹wp-content\themes\goodblog下面新建一个头部文件header.php,然后将index.php中的头部代码提取(剪切)出来,写入这个文件:

第二步:修改index.php

保存好头部文件,在index.php的前面加上代码:

get_header()函数会自动载入主题文件夹中的header.php文件,所以头部文件的文件名命名为header.php然后使用get_deader()函数即可;

现在头部文件已经制作好了,接下来的工作就是编辑头部文件header.php将里面的静态html代码换成动态的php代码。


第三步:修改title

需要更改信息,一般我们将title信息改成这样的: 文章页面标题 | 网站名称,当然用户也可以根据自己的seo只是更改,比如有的人在标题中加入网站描述。将header.php中的index改成下面的代码:

上面的代码通过判断将首页、文章页、分类页、404页面的信息设置成不一样的形式,这样是很有必要的。<br>几个判断函数的解释如下:</p> <p><img loading="lazy" class="ikqb_img" src="/picurl?url=https%3A%2F%2Fiknow-pic.cdn.bcebos.com%2F8b13632762d0f70316b63fdc0ffa513d2697c5ae%3Fx-bce-process%3Dimage%252Fresize%252Cm_lfit%252Cw_600%252Ch_800%252Climit_1%252Fquality%252Cq_85%252Fformat%252Cf_auto" esrc="https://iknow-pic.cdn.bcebos.com/8b13632762d0f70316b63fdc0ffa513d2697c5ae"></p> <p>第四步:修改css文件的路径</p> <p>在header.php文件中找到下面代码:</p> <p><img loading="lazy" class="ikqb_img" src="/picurl?url=https%3A%2F%2Fiknow-pic.cdn.bcebos.com%2F3bf33a87e950352a7fda8f085443fbf2b2118b73%3Fx-bce-process%3Dimage%252Fresize%252Cm_lfit%252Cw_600%252Ch_800%252Climit_1%252Fquality%252Cq_85%252Fformat%252Cf_auto" esrc="https://iknow-pic.cdn.bcebos.com/3bf33a87e950352a7fda8f085443fbf2b2118b73"></p> <p>这个样式表的路径./style.css是网站根目录。</p> <p>如果用户不想让别人轻易看出用户网站是使用 wordprss程序,那么可以改变图片、样式表等文件的路径,比如本工作室,将图片、样式表都移到了网站根目录,在网页代码中就不会出现 wordprss站才有的wp-content/themes之类的路径。好了,将上面的代码改成:</p> <p><img loading="lazy" class="ikqb_img" src="/picurl?url=https%3A%2F%2Fiknow-pic.cdn.bcebos.com%2F472309f790529822eaef93c3d0ca7bcb0b46d4d6%3Fx-bce-process%3Dimage%252Fresize%252Cm_lfit%252Cw_600%252Ch_800%252Climit_1%252Fquality%252Cq_85%252Fformat%252Cf_auto" esrc="https://iknow-pic.cdn.bcebos.com/472309f790529822eaef93c3d0ca7bcb0b46d4d6"></p> <p>bloginfo('stylesheet_url')会自动输出网站主题文件夹下style.css文件的绝对网址,如http://localhost/wordPress/wp-content/themes/goodblog/style.css</p> <p>说到这里,顺便修改一下图片路径,在index.php里有张图片路径需要修改,不过现在可改可不改,后期会自动调用文章图片;</p> <p>用文本编辑器打开index.php给这些图片加上正确的URL,搜索代码,将所有的:src="images/,批量替换成src="<?php bloginfo('template_url'); ?>/images/。现在再刷新你的主页,看文章的缩略图是否可以正常显示。</p> <p><br></p> <p>第五步:关于wp_head()</p> <p>wp_head函数对于要使用插件的主题来说比较重要,一般如果插件需要加载css文件和js文件,都是通过wp_head()函数输出的。在header.php文件的</head>前面添加:</p> <p><img loading="lazy" class="ikqb_img" src="/picurl?url=https%3A%2F%2Fiknow-pic.cdn.bcebos.com%2F63d9f2d3572c11df28cb2a23642762d0f703c29c%3Fx-bce-process%3Dimage%252Fresize%252Cm_lfit%252Cw_600%252Ch_800%252Climit_1%252Fquality%252Cq_85%252Fformat%252Cf_auto" esrc="https://iknow-pic.cdn.bcebos.com/63d9f2d3572c11df28cb2a23642762d0f703c29c"></p> <p>在去看自己的网站,查看网页源代码,会发现<head></head>标签中多了如下代码:</p> <p><img loading="lazy" class="ikqb_img" src="/picurl?url=https%3A%2F%2Fiknow-pic.cdn.bcebos.com%2F0b46f21fbe096b63695ecb500b338744ebf8ac6f%3Fx-bce-process%3Dimage%252Fresize%252Cm_lfit%252Cw_600%252Ch_800%252Climit_1%252Fquality%252Cq_85%252Fformat%252Cf_auto" esrc="https://iknow-pic.cdn.bcebos.com/0b46f21fbe096b63695ecb500b338744ebf8ac6f"></p></p> </div> </div> <div class="clear"></div> </div> <div class="wdhdnr"> <div class="huidanrtop"> <div class="wdhuidaxinx"> <div class="wdhuidaxm">回答2:</div> </div> </div> <div class="clear"></div> <div class="wdhuidanrmid"> <div class="zuijiacont"> <p>import java.io.BufferedReader;<br>import java.io.InputStreamReader;<br>class test <br>public static void main(String[] args) throws Exception<br>BufferedReader br=new BufferedReader(new InputStreamReader(System.in));<br>String str=null;<br>System.out.print</p> </div> </div> <div class="clear"></div> </div> </div> </div> <div class="wendaright"> <div class="wdluluerwema"> <div class="wdxgwttop">相关问答</div> <div class="wdxgwtnr"> </div> <div class="clear"></div> </div> <!-- 其他随机问答['id'=>alphaID($like['zid'])] --> <div class="wdluluerwema"> <div class="wdxgwttop">最新问答</div> <div class="wdxgwtnr"> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/73050774.html">我想买个房子,请明白人进来帮我解答一下</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/405207850.html">小弟毕业生,网投简历后,今天收到中国铁建中铁十五局集团有限公司邀请函 不知道是真是假 忘前辈告知,谢</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/169659893.html">南京。云南。湖北。这三个地方哪个好</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/1820487993318965828.html">我喜欢我的一个女同事怎么办?她36岁是离婚的,我26岁单身</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/146480353.html">中航锂电怎么样?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/472603108.html">看武汉新航道官网好多高分学员啊,真的有那么大的提高啊</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/350615945.html">一道ACM题 求代码!!做出者有奖!!!!!!!!</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/380344625.html">线切割火花很小速度也很慢怎么调也调不好怎么回事急急!</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/576054694.html">嘉定长途汽车站到常熟汽车站时刻表</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/525488538927540845.html">58同城属于什么行业</a></div> </div> </div> </div> </div> <div class="clear"></div> <div class="footer"> <!-- 移动底部导航 --> <div class="fanhuitop"><a href="#top" ref="nofollow"><img src="https://www.g230.com/static/old/img/fhtop.png" alt="返回顶部" title="返回顶部"></a></div> <div class="dibu"> <div class="dibu"> </div> </div> <div class="banquan"> <p>内容全部来源于网络收集,如有侵权,请联系网站删除:QQ:24596024</p> </div> </div> </div> </div> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?78733b427b0a9dce19688d903e89fc12"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>