Support » How-To and Troubleshooting » [Resolved] i want add shortcode 'URL' with forum syntax..

[Resolved] i want add shortcode 'URL' with forum syntax..

  • hi,
    sorry for my bad english.
    I read on wordpress codex the correct syntax for add a shortcode, but i have not found solution, maybe you can help me 🙂

    i want add this codex with this syntax
    know how to add the syntax if I wanted to be this
    [url url="http://example.com/"]text[/url]
    but I’m looking for a way to use the first, in order to lighten the work of many

    i try it

    function wp_shortcode_url($attr, $content){
     return '<a href="'.$attr[0].'" class="bbcode-url">'.$content.'</a>'.$content;
     add_shortcode( 'url', 'wp_shortcode_url');

    but dont work, please, help me 🙂

    thanks 1000 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • I was thinking that you could use the filter
    <? php add_filter ('the_content', 'filter_function_name')?>
    and regular expressions ..
    anyone can ‘write the function with regular expressions?

    Moderator keesiemeijer


    Try it without the “equal” operator and without the trailing slash in the url (or add a space after it)

    [url http://example.com]text[/url]
    [url http://example.com/ ]text[/url]

    WordPress thinks it’s a self enclosing shortcode with the closing slash:

    [myshortcode attr="attribute" /]


    function add_my_link( $atts, $content = null ) {
      if((isset($atts[0]) && $atts[0]) && $content) {
    		return '<a href="'.esc_url((string) $atts[0]).'" >'.$content.'</a>';
    add_shortcode( 'url', 'add_my_link' );

    thanks, but i want use syntax forum , without space and with equal.

    i find solution

    function wp_shortcode_url($content){
     $pattern = '/\[url=(.+?)\](.+?)\[\/url\]/i' ;
     $replacement = '<a href="$1" class="bbcode-url">$2</a>';
    $content = preg_replace($pattern, $replacement, $content);
     return $content;
    add_filter( 'the_content', 'wp_shortcode_url' );

    work 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] i want add shortcode 'URL' with forum syntax..’ is closed to new replies.