1

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?

2 Answers 2

3

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>';
    }
0

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.

4
  • I have 500 pages with this kind of shortcodes so I would like to use function than changing it manually Commented Jun 21, 2019 at 14:04
  • what do you want your function to do ?
    – Maneza F8
    Commented Jun 21, 2019 at 14:06
  • [mybutton] to <a href="#"> [/mybutton] to </a> Commented Jun 21, 2019 at 14:07
  • No that will not work, the button will not show if you do that... try <a href="#">[mybutton]click there[/mybutton]</a> I hope it works
    – Maneza F8
    Commented Jun 21, 2019 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.