
-
AuthorPosts
-
May 12, 2025 at 12:18 pm #1484085
Hello,
we use the masonry element to show / select posts according to the post tags – this works great.When somebody clicks on the “selector” (=post tag) offered by the masonry, a “#” is added to the URL.
Is there a way to have the “valid” / “complete” URL?
Thus we could use the link to the page with the selected tags of the Masonries, something like this: https://link-to-website/page-with-masonry?%5Bpost-tag%5D
The result would be the link to the proper web page with the pre-selected post tag.Is this possible?
May 13, 2025 at 5:18 am #1484125Hey Jochen,
Thank you for the inquiry.
This should be possible with a custom script. Please try this code in the functions.php file:
add_action( 'wp_footer', 'auto_click_sort_button_by_tag', 100 ); function auto_click_sort_button_by_tag() { ?> <script> document.addEventListener("DOMContentLoaded", function () { const urlParams = new URLSearchParams(window.location.search); const tag = urlParams.get("tag"); if (tag) { const buttonClass = tag + "_sort_button"; const button = document.querySelector("." + buttonClass); if (button) { button.click(); } } }); </script> <?php }
This should automatically activate the corresponding masonry sorting button based on the value of the ?tag= parameter in the URL. For example:
https://site.com/masonry?tag=images
Best regards,
IsmaelMay 13, 2025 at 12:55 pm #1484150Hello Ismael,
thanks for your reply, but this doesn’t work as expected.
When I click on the selevtion of the masonry, I get the correct “filtered” results.
When I add /masonry?tag=my-tag to the URL, I get a different result.I’ve sent you more details in the private section.
Any idea ?
Thanks a lotMay 14, 2025 at 5:49 am #1484185Hi,
Thank you for the update.
What happens when you replace the URL param with sort_tag or something else other than tag? We may need to access the site to properly test the modification. Please provide the login details in the private field.
Best regards,
IsmaelMay 14, 2025 at 10:51 am #1484219Hi Ismael,
thanks for your reply.
When we change the URL param with e.g. ?tag=sort_tag, we get the unfiltered outout – all posts are shown.I inserted the login details in the private section.
Thanks a lot,
Jochen-
This reply was modified 2 weeks, 6 days ago by
jochenmaier.
May 15, 2025 at 6:17 am #1484266Hi,
You may have forgotten to include the password. Please post the info in the private field.
Have you tried using ?sort_tag=inbound?Make sure to update this line with the correct parameter name.
const tag = urlParams.get("tag");
Best regards,
IsmaelMay 15, 2025 at 9:58 am #1484293Hello Ismael,
I assumed you were using the “forgot password” function to create your own password. I have stored a password in the hidden section.When I change the code in the functions.php to
const tag = urlParams.get(“inbound”);
and add ?sort_tag=inbound? to the equivalent URL, it doesn’t work.What I would like to achieve:
We use a masonry that can be filtered according to the tags. This works fine.
I’d like to able to have a link that directly sets the masonry filtering to the appropriate tag.Thanks a lot
May 16, 2025 at 6:43 am #1484317Hi,
We modified the script in the functions.php file a bit. It should be working correctly now. Please make sure to purge the cache or remove the browser history before testing. (see private field)
/* Masonry erweitern */ add_action( 'wp_footer', 'av_click_sort_button_by_tag', 100 ); function av_click_sort_button_by_tag() { ?> <script> (function ($) { $(function () { const urlParams = new URLSearchParams(window.location.search); const tag = urlParams.get("sort_tag"); console.log(tag); if (tag) { const buttonClass = tag + "_sort_button"; const button = $("." + buttonClass + " .inner_sort_button")[0]; console.log(button); if (button) { button.click(); } } }); })(jQuery); </script> <?php }
Best regards,
IsmaelMay 20, 2025 at 11:09 am #1484490Dear Isamel,
thanks a lot for the great support – you may close this ticket. 👍
May 21, 2025 at 5:37 am #1484509 -
This reply was modified 2 weeks, 6 days ago by
-
AuthorPosts
- The topic ‘Question on Masonry’ is closed to new replies.