Blog Posts

Creating a dynamic link with page URL or custom data

MaxButtons PRO – Version 8.3+

Occasionally it’s needed to include a dynamic link that takes it’s information from the current page context. For instance when you want to include the URL.

MaxButtons PRO version 8.3 introduces the option to use variables in the link field. It’s denominated by the || character.

Dynamic link example with variable
Example usage for a variable using ||

When the button loads on the frontpage, the plugin will try to find the current permalink of the page or post and put the value into the link.

Currently MaxButtons PRO supports two different variables: permalink ( ||permalink || ) and pageurl ( ||pageurl|| ).

The difference between the two is that the pageurl refers to the URL of the main document, while the permalink refers to the URL of the current item inside the WordPress Loop.

We intend to add more variables in upcoming versions. If you feel you need another variable that could be of common use in MaxButtons, please contact our support!

Using custom data in the link

If you are using custom field / other plugins or you have data you want to put into the button link, you can do so by using the a hook we included. See this example:

<?php add_filter('maxbuttons/parse/variable', function($result, $content) {
    if ($content == 'myvariable')
        $result = get_the_title(); 
    return $result; 
}, 10,2 ); 

In this example we have the variable ‘myvariable’ get the current title of the page / the loop item. With this snippet in your functions.php ( you can use a snippet plugin for this ) you can now use ||myvariable|| in the button. editor link field.

You can use any field or code that’s available in the context. This also includes functions for instance to use with ACF and data from other plugins.

Note that when using this type of variables the placement of the button becomes important. Not on all places in your post or page the same variables might be available.