If you are using Tags in Mailster you may like to use them in your links as well. Since links must be encoded the content of your tags must be encoded as well.

To encode the output of the tag with PHP rawurlencode you have to prepend an exclamation mark (!) before the name of the tag:

{!mytag}

Example

Let’s assume you have a custom dynamic tag called mytag which returns some special characters:

add_action( 'mailster_add_tag', function(){

    mailster_add_tag('mytag', function() {
         return 'Please encode me: ! * \' ( ) ; : @ & = + $ , / ? % # [ ]';
    });
    
});

Using {mytag} in your email outputs:

Please encode me: ! * ‘ ( ) ; : @ & = + $ , / ? % # [ ]

while using {!mytag} will output:

Please%20encode%20me%3A%20%21%20%2A%20%27%20%28%20%29%20%3B%20%3A%20%40%20%26%20%3D%20%2B%20%24%20%2C%20%2F%20%3F%20%25%20%23%20%5B%20%5D

You can still use {mytag} in your campaign but whenever you like to use a tag as a query argument in a link you should go with {!mytag}.

https://example.com?query={!mytag}

will output:

https://example.com?query=Please%20encode%20me%3A%20%21%20%2A%20%27%20%28%20%29%20%3B%20%3A%20%40%20%26%20%3D%20%2B%20%24%20%2C%20%2F%20%3F%20%25%20%23%20%5B%20%5D

Don’t use this method for tags containing whole links!

If you have a whole link in your tag you should not use the exclamation mark:

<a href="{unsublink}">{unsublinktext}</a>;
<a href="{profilelink}">{profilelinktext}</a>;
Tagged: