0

In WordPress, is it possible to retrieve the part of the URL after a #?

I'm trying echo the_slug(); but it's showing front slug. But I want after #tag

For example: I'm searching and land on this page. And print last anchor text.

http://www.mywebsite.com/test/#test1 >> Output: test1

http://www.mywebsite.com/test/#test-test2 >> Output: test-test2

1
  • the_slug() is no native WordPress function... where does it come from?
    – kaiser
    Commented Jul 25, 2014 at 10:27

1 Answer 1

0

First off, the "slug" is what it is by definition. There is no such thing as a "front slug".

As you do not elaborate/know on how the anchors/hashes are generated on the server side, all I can give you is a JS solution (proof of concept):

if (window.location.hash) {
    alert(window.location.hash.substring(1));
}
5
  • Hi Pille, no It's not server side. Anchors/hashes give from backend only for admin. And I'm display (mywebsite.com/test/#test1) test1 in this page.
    – vino
    Commented Jul 25, 2014 at 4:43
  • The backend does not "give" anchors just like that. I have a distinct feeling you have no idea what "server side" means. Sorry to say. Try to use the above. Best solution I can give you. Commented Jul 25, 2014 at 4:56
  • Sorry Pille, I'm not well programming. But your answer is correct. Now showing fine. Thanks.
    – vino
    Commented Jul 25, 2014 at 5:08
  • You have any idea? How put this value in PHP variable.
    – vino
    Commented Jul 25, 2014 at 5:11
  • PHP == server side --> You need to figure out where it comes from / is generated. Commented Jul 25, 2014 at 5:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.