Shortcode But Without The Equals Sign?

I am aware of creating a shortcode this way:

function font_fam($atts, $content = null){ 
extract(shortcode_atts(array(
  'f' => '',  
  ), $atts ));

return '<span style="font-family:'.$f.'">'.$content.'</span>';

}
add_shortcode ('f','font_fam');

And to use it would be like this right:

Read More
[f f="Arial"] Text Text [/f]

But is there a way so that it will be used like this:

[f Arial] Text Text[/f]
[f Tahoma] Text Text [/f]

(skipping the “f=”)

Thanks!

Related posts

Leave a Reply

2 comments

  1. Try this:

    function font_fam($atts, $content = null) {
    
        extract(shortcode_atts(array(
                'f' => isset($atts[0]) ? $atts[0] : '' ,
                ), $atts));
    
        return '<span style="font-family:' . $f . '">' . $content . '</span>';
    }
    
    add_shortcode ('f','font_fam');
    
  2. One way could be to preparse your content by hooking a ‘the_content’ filter that adds the f= bit.

    Another could be to change your shortcodes to something like [Tahoma]...[/Tahoma] and skip the f altogether, although then you end up registering a lot of shortcodes.