Joomla Anchor

joomla logo blackTo add an Anchor in Joomla in an article is quite simple, just add

<a href="/my-anchor"></a>

to your article code, then link to it from elsewhere on your article

<a href="#my-anchor">Link test</a>

However, if you want to use it to point to a specific point in an article from a MENU Item, this is not easily possible.

You would think that by changing the menu type to external link and including the #my-anchor at the end of the article link it would but on my Joomla installation, it crashed the page.

So, I searched high and low until I found a forum post somewhere on the internet that offered a working solution.

Add the following code snippets to your Joomla template source code:-

Replace:

<body>

with

<body onload="goToAnchor();">

 

Replace

</head>

 

with

<script type="text/javascript">
 function goToAnchor() {
 location.href = "#my-anchor";
 }
 </script>
 </head>
 

Now, as long as the anchor name you use is unique to the article that you wish to scroll to upon loading the page this code can be placed within your template for use on any page. It will only work on the page with the actual anchor in an article.