Viewing 18 posts - 1 through 18 (of 18 total)
  • Author
    Posts
  • #765814

    Hi,

    We need to change where the primary logo links to (which is different than what’s listed under “WordPress Address (URL)” and “Site Address (URL)” under Settings > General).

    What’s the best way to do this?

    Thank you!

    #765873

    Hey franktw,

    Try adding this code at the bottom of functions.php:

    function change_logo_link(){
    ?>
    <script type="text/javascript">
    (function($){
      function change_logo_link() {
        jQuery("#header_main").find(".logo a").attr("href", "http://www.google.com/");
      }
    
      change_logo_link();
    })(jQuery);
    </script>
    <?php 
    }
    add_action('wp_footer', 'change_logo_link');

    Hope this helps :)

    Best regards,
    Nikko

    #766346

    Thanks. I think I know the answer, but is there any way to do this without modifying code?

    #766443

    Hi,

    No, I think this is the easiest way to do it. The other way would be using a child theme, copy and paste header.php and tweak it :)

    Best regards,
    Nikko

    #766626

    We really don’t like modifying core code or functions.php but are happy to inject code using a plugin framework (i.e. simply adding functions/code to a simple plugin and installing that plugin).

    Can you (or anyone else) think of a way to change the logo link destination via PHP code / function that can be installed via the plugin framework (so we can keep the code separate)?

    Thanks!

    #766807

    Hi,

    Please use a child theme to add your modification :)

    Best regards,
    Vinay

    #767062

    Yes, I know that’s possible but we were hoping to use an external function in a Plug-In rather than having to deal with a Child Theme and the management thereof. If there’s a way to use a self-contained function we can add to a plug-in, that would be ideal.

    #767077

    Hey!

    You can create a plugin
    https://codex.wordpress.org/Writing_a_Plugin

    and add the code there, if that works out for you

    Regards,
    Basilis

    #767094

    Thanks. Could you provide a variant of the function (listed above) that can be put in that plugin?

    Thanks again!

    #767154

    Hi,

    You might want to check this post: https://www.doitwithwp.com/create-functions-plugin/

    Best regards,
    Nikko

    #767513

    Thanks. I understand how to create the plugin, just need a modification of the code you posted above so it can work standalone in the plugin.

    Thanks again!

    #768177

    Hi,

    Please add following code to Functions.php file in Appearance > Editor to change logo link as needed

    add_filter('avf_logo_link','av_change_logo_link');
    function av_change_logo_link($link)
    {
        $link = "http://kriesi.at";
        return $link;
    }

    Best regards,
    Yigit

    #1037305

    Is it possible to open my custom logo-link in a new tab?

    Best regards

    #1037827

    Hi Bewohnerfrei,

    Could you please give us a link to your website, we need more context to be able to help you.

    Best regards,
    Victoria

    #1079288

    in this case i would not take the elegant way over the filter but combine all attributes in one rule:
    ( You see how it works? – every new attribute is comma separated (except the last one) )

    function custom_logo_attriubtes(){
    ?>
    <script>
    (function($){
    	$('.logo a').attr({ 
    		"href": "https://your-domain", 
    		"target": "_blank", 
    		"title": "custom_title", 
    		"alt": "custom_alt" 
    		});
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'custom_logo_attriubtes');


    PS
    on those attributes you do not need to have arround href or targe the double quotes. But on others ( f.e. data-attributes ) you do – so if you don’t like to rembember where to use and where not – use them allways

    #1079554

    Hi,

    Thanks for helping out @guenni007 :-)

    Best regards,
    Rikard

    #1289730
    This reply has been marked as private.
    #1289847

    Hi,


    @alfonsosdc
    glad you figured it out! Let us know if you have any other questions or issues and enjoy the rest of your day :)

    Best regards,
    Yigit

Viewing 18 posts - 1 through 18 (of 18 total)
  • You must be logged in to reply to this topic.