Shortcodes with Attributes

Post Reply
User avatar
Kygo Founder
Founder
Founder
Posts: 339
Joined: 26 Sep 2024, 22:31
Has thanked: 3 times
Been thanked: 31 times
Contact:
    unknown unknown
Dec 2024 27 14:49

Shortcodes with Attributes

Post by Kygo Founder

To create a shortcode for links, we need to include the attribute information as well as the anchor text for the link itself. We can do this by placing this function in your theme’s file:hreffunctions.php
Please Login or Register to see this code Then, when creating a post, emulate the following format to include any links you wish:

[link href="https://perishablepress.com/"]Perishable Press[/link]

..which will output the following code:

<a href="https://perishablepress.com/">Perishable Press</a>

When the attribute is removed from the shortcode, the default URL will be used. You may specify the default URL in the third line of the funtion (see comment).href

Post Reply