How to get after hash word from current page url

I’ve been developing a filtering with mixitup including hash url filtering support in WordPress. But one of the task, I need to catch up the after hash word and have to pass it into pure php string as variable. Like has this url and I want to get that “#slug_1” only.

I’ve tried with the following javascript code to catch the hash word and passed it into php like the following format.

<script>var hash = location.hash;</script>
<?php $hash_value = “<script>document.writeln(hash);</script>”;

After that, the hash value stored in that php variable but it didn’t work on any html inside tag where have another quotation mark on the wrapper of this variable. It showed the direct script there.

<a href=”<?php $hash_value; ?>”>Something</a><script>document.writeln(hash);</script>

So my question is, how can I achieve that value so that I can use it on any place with php?

If I have to use ajax to get that value, then could anyone please tell me a bit briefly about this process because I’m making this whole thing as shortcode as well from function file.


Read more here:: How to get after hash word from current page url

Leave a Reply

Your email address will not be published. Required fields are marked *