I have a site on WordPress, and first of all I have this PHP shortcode that helps me to make customizable links in WP post editor without turning my CSS files into a dump of classes with basically the same parameters.
function custom_link($atts, $custom_title)
{
$url = $atts[url];
$color = $atts[color];
$icon = $atts[icon];
return '<a class="button-round custom-link" style="background-color: #' . $color . ' !important" href="' . $url . '" target="_blank">' . $icon . '<span>' . $custom_title . '</span></a>';
}
add_shortcode('custom-link', 'custom_link');
It lets me to put custom $url
, background color of the button $color
and icon $icon
. It supposed to turn out like this, for example:
The problem is with $icon
. Basically I have a separate PHP file full of variables with respectable SVG codes of icons set for them, let's get one of them, for example, $icon_paypal
. I want the $icon
variable to become the value of icon
attribute of custom-link
I set:
[custom-link url="/someurl" color="#092F87" icon="paypal_icon"]Donate[/custom-link]
So after that the return should be like this:
<a class="button-round custom-link" style="background-color: #' . $color . ' !important" href="' . $url . '" target="_blank">' . $icon_paypal . '<span>' . $custom_title . '</span></a>
...and then executed into a proper HTML code.
I'm a beginner in PHP, hopefully I explained my issue as exhaustively as I could.