I have a website with a lot of
[mybutton]click here[/mybutton]
or
[mybutton]click there[/mybutton]
in editor. I need to add a function to create a href from this shortcodes. Closing of shortcode is a problem for me. How can i do it?
To change the functionality of a shortcode you must first remove_shortcode( 'shortcode_name' );
where shortcode name is the name of the shortcode. Add the shortcode back with your NEW function.
A simple example to follow what you might be needing:
remove_shortcode( 'mybutton' );
add_shortcode( 'mybutton', 'my_shortcode_function' );
my_shortcode_function( $atts, $content = "" ) {
return '<a href="http://example.com">' . $content . '</a>';
}
That is a short code not HTML you can put any Attribute there, if you want that function got to your page builder and insert a text editor and to html editor and create a button so you can put any attribute you want in it.
<a href="#">[mybutton]click there[/mybutton]</a>
I hope it works
Commented
Jun 21, 2019 at 14:12