Tagged: ,

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #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?

    #1484125

    Hey 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,
    Ismael

    #1484150

    Hello 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 lot

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.