简体   繁体   English

我想更改 wordpress 网站中 logo 的 href 链接

[英]I want to change the href link of logo in wordpress website

I have use roccochoco theme in wordpress and now i want to change the url of logo that other than the home page.我在 wordpress 中使用了 roccochoco 主题,现在我想更改除主页之外的徽标的 url。 i tried this code but that doesn't work $(document).ready(function(){ $("a.custom-logo-link").attr("href", "https://"); });我试过这段代码,但不起作用$(document).ready(function(){ $("a.custom-logo-link").attr("href", "https://"); });

please help me out and thanks in advance请帮助我并提前感谢

In Wordpress using jQuery with $ often doesn't work, because it is used internally.在 Wordpress 中,使用带有$的 jQuery 通常不起作用,因为它是在内部使用的。 The console might show you a warning saying "$ is not a function".控制台可能会向您显示“$ 不是函数”的警告。 You can put it inside of a function to make it work.你可以把它放在 function 里面让它工作。 Your element is selected by class, so the name of the class is enough.您的元素是由 class 选择的,因此 class 的名称就足够了。

( function( $ ) {
    $(".custom-logo-link").attr("href", "https://www.newurl.com");
}( jQuery ) );

Another way to achieve it without using Javascript would be to edit the header.php file of your theme.在不使用 Javascript 的情况下实现它的另一种方法是编辑主题的header.php文件。 If you want to keep your theme updatable, you should create a child theme (it is done in one minute with creating an empty folder and putting a style.css with some info in), copy the header.php of your parent theme in the folder and delete the part in the <a> tag, looking like get_home_url() .如果你想让你的主题保持可更新,你应该创建一个子主题(创建一个空文件夹并放置一个 style.css 并在其中包含一些信息),复制 header.ZE1BFD762321E409CEEZAC0B6 中的父主题文件夹并删除<a>标记中的部分,看起来像get_home_url()

After the DOM is loaded, we can set the href of the anchor having custom-logo-link class to point to the URL you prefer:加载DOM后,我们可以将具有custom-logo-link class的锚的href设置为指向您喜欢的URL:

jQuery(document).ready(function(){    
  jQuery("a.custom-logo-link").attr("href", "https://www.domainname.com"); 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM