Hi there I am new to coding and trying to accomplish a very simple task that has thus far gotten the better of me.
I had my logo which is housed in the page header, linked to the homepage in the editor panel, I then had to write some code so that the logo did not appear on certain pages this seems to removed the link capability.
Any ideas how to restore the logo link function to navigate to home page once clicked, I have been trawling through the forum from morning with little luck, the below code is the closest I have gotten but still does not work.
Any help extremely appreciated.
import wixLocation from ‘wix-location’;
// …
export function SMLOGO_click(event) {
wixLocation.to(“/”);
}
Just set the link up through the image element itself.
https://support.wix.com/en/article/adding-a-link-to-an-image
That way it won’t matter if your logo in your header is set to be hidden on some pages or not.
Many thanks for the quick response, I have attempted that numerous times with no success. In my limited understanding it seems there is a conflict as I am giving the Image 2 sets of instruction one from the editor panel, another through corvid.
The header is not set to be hidden only the image.
If you have the image in your header, then it will appear on all your pages that you have a header on.
So, on the specific pages that you want the image in your header to not be shown, then you can simply code your page like this for example.
$w.onReady( () => {
$w("#headerimage").hide();
});
Then you can simply have the link for the homepage on your image element itself through the Wix Editor link settings.
Or you can do what you have already done and put the onClick event in your code, with the event handler function through the properties panel for the image.
With onClick added through properties panel.
import wixLocation from 'wix-location';
$w.onReady(function() {
});
export function SMLOGO_click(event) {
wixLocation.to("/");
}
Finally, if the use of the “/” does not work for taking the user back to your home page, as it should do in the Wix Location API .to() function.
Description
The to() function navigates the browser to another web page.
The following link patterns are supported:
-
/localPageURL: Another page on your site.
-
/localPageURL#: Another page on your site scrolled to the element with the specified ID. The element must be an element that supports the scrollTo function.
-
/localPageURL?queryParam=value: Another page on your site with query parameters.
-
/: Your site’s home page.
-
http(s)://: An external web address.
-
wix:document://: A document stored in the Media Manager.
-
mailto:@<someplace.com>?subject=: An email.
-
tel:: A phone number.
Then simply replace the “/” with your own home page url - “/homepage” for example.
Plus, with regards to your comment of…
In my limited understanding it seems there is a conflict as I am giving the Image 2 sets of instruction one from the editor panel, another through corvid.
Then yes you are correct if you try to link an element on your page with a link through the Wix Editor link settings and through Wix Corvid too.
Do not use the Editor Link panel to redirect on click when a link is already defined using the onClick() function. To avoid unpredictable behavior, remove the link from the Editor Link panel.
Thanks @GOS I attempted both methods to link the element and I am getting a “Parsing error unexpected token” etc?
I attempted deleting the red underlined elements, but the error just moved on to the next.
Yes my mistake it should be like this…
import wixLocation from 'wix-location';
$w.onReady(function() {
});
export function SMLOGO_click(event) {
wixLocation.to("/");
}
Always pays to check your code!
Thanks for your time mate really appreciate it, I have made the adjustment and still no luck.
I may be missing something obvious, here is the live site www.seraphmundus.com
thanks again.
This is the only other bit of code I have located in the “page” tab which hides and shows the image.
I tested the code on a new blank website and it does work, just obviously it won’t work if you are on your home page as it is already on it.
import wixLocation from ‘wix-location’;
$w.onReady( function () {
});
export function SMLOGO_click(event) {
wixLocation.to(“/”);
}
Also, note that in your last picture you have the image elements own link setting in green, which means that you have linked it through the Wix Editor itself.
So, as previously stated, you can’t use the two links both at the same time.
You either use the elements own link with the hide code on specific pages.
Or you use hide code on specific pages with the image onClick event on your site code tab.
The screen shot was just to illustrate the code, the code to link the logo to the homepage is in the site tab so should run on all pages.
To control for my exact environment did you place the image on multiple pages then hide it on one?
Because this still doesn’t work on my side, you have verified the screenshot, but if you go on my website you will find that clicking on the logo does nothing.
Thanks in advance.
All the links have been set to none.
I unattached the image from the header, ran the code then re-attached it and now works!
Many thanks for your time absolute legend.