PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 3, 2022

[FIXED] How to replace instance of WordPress home_url hyperlink via functions.php

 July 03, 2022     multisite, php, wordpress-theming     No comments   

Issue

The WordPress theme I'm using applies a home_url() link to the header logo and I'd like to change it to network_home_url()... Easy enough if I am editing the theme files but I'd like to do it via the child theme functions.php file so I can keep all my tweaks separate from the main theme (it's a multisite installation).

This is what I'm working with (albeit simplified):

<div class="logo">
    <a href="<?php echo home_url(); ?>">
        <img src="/image.png">
    </a>
</div>

I've tried the following, which worked but resulted in a site-wide change (including WP settings, etc) which in turn broke all the permalinks:

add_filter('home_url', 'change_logo_link');
function change_logo_link($output) {
    return network_home_url();
}

Is there a way I can target that specific hyperlink without editing the parent theme files? I don't think the home_url function is used anywhere else in the theme so it doesn't need to be too specific, I just want to avoid affecting the WP settings.

Thanks in advance!!!


Solution

The concept of child themes is to allow customizing of almost everything without changing the parent theme. Just copy your parent theme's template file with that logo code to your child theme's folder and replace home_url() with network_home_url(). WordPress will use that modified child template instead of parent one if you activate this child theme on your network site.



Answered By - Ihor Vorotnov
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,208,635

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing