[Support request] Setting dynamic links on block elements

Home Forums Support [Support request] Setting dynamic links on block elements

Home Forums Support Setting dynamic links on block elements

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2064975
    Luke

    We have set up a block element with a number of buttons linking to various pages on our site. These will change depending on what posts you’re viewing. Is there a way to set up a dynamic link on these buttons to change where the link takes us based on our own custom rules?

    For example, we are currently using the render_block hook to update the text of the button, but aren’t able to update the href of the button/link. This button will take us to the next post unless we have specified our own “next post” with an ACF field. We can get the button to show the name of our custom next post, but not able to link it.

    #2065073
    Ying
    Staff
    Customer Support

    Hi Luke,

    If I understand correctly, you just need to use the dynamic text and dynamic link option of the block element.
    Choose post metaas dynamic text type and dynamic link type.
    Fill the meta field name.

    For example:
    Block settings:
    https://www.screencast.com/t/39PRBrVU846O

    Post custom field:
    https://www.screencast.com/t/QTYgnOYl

    #2067395
    Luke

    Thank you for your reply!

    The links that we are needing to use are coming from a function that also checks if and when a link should be shown.

    For example, our function would check to see if an ACF field is present with a value and return the permalink for the chosen post. Else it would return the default adjacent post if one exists, else it would return a default value for the link (A pre-selected post).

    Not only that, but we are looking for the container link to be updated, and not the dynamic text itself. This way if we were to use a button block, the entire button would be clickable, and not just the text in the middle. We’re using GenerateBlocks-Pro to give us the ability to add container links.

    Thanks,

    #2067462
    David
    Staff
    Customer Support

    Hi there,

    if the links are being generated by a function then there is no way for the GPs dynamic data to find them, it can only look for stuff in a database.

    Instead you would need to output those links using a Shortcode that can be added inside the block element.

    Adding the container link wrapper would rely on some CSS to make that work. Happy to help with that.

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