Shortcode to find and replace URL

Your shortcode function should look like this: function replace_url_for_nonlogged( $atts, $content = “”) { if ( is_user_logged_in () ) return $content; extract( shortcode_atts( array( ‘replace’ => ‘http://www.default_replace_url.com’, ), $atts ) ); $pattern = ‘/href=(“|\’)((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)(“|\’)/’; return preg_replace($pattern, “href=\”$replace\””, $content); } add_shortcode( ‘scode’, ‘replace_url_for_nonlogged’ ); Then you can use the shortcode like this: [scode]Lorem <a href=”http://reservedurl.com”>ipsum</a> dolor … Read more

Displaying shortcode output through Options Framework

You should check out the WordPress function do_shortcode(). You can use it to generate the shortcodes, in a string variable, like this : <?php echo do_shortcode( $content ) ?> So in your case, please try: <?php if ( of_get_option(‘footer_contact_form’) ) { echo do_shortcode( of_get_option(‘footer_contact_form’) ); } ?>

Adding an option to a shortcode

Regarding Edit #3 I would rewrite it like this: //* Shortcode for getting users function list_of_users( $atts ) { extract( shortcode_atts( array( ‘display’ => ‘all’, ‘user’ => ’30’ ), $atts )); $content=””; switch ( $display ) { case ‘all’: $content = display_all_users(); break; case ‘single’: $content = display_single_user( (int) $user ); break; default: break; } … Read more

Get attributes of nested shortcodes

Since nobody posted a complete answer, I used the method s_ha_dum described and written a function that returns a shortcode => attributes array/map. function attribute_map($str, $att = null) { $res = array(); $reg = get_shortcode_regex(); preg_match_all(‘~’.$reg.’~’,$str, $matches); foreach($matches[2] as $key => $name) { $parsed = shortcode_parse_atts($matches[3][$key]); $parsed = is_array($parsed) ? $parsed : array(); if(array_key_exists($name, $res)) … Read more

How do I make a shortcode?

Like this: add_shortcode(‘SHORTCODE_NAME’, ‘SHORTCODE_NAME_shortcode’); function SHORTCODE_NAME_shortcode() { // PUT YOUR CODE HERE } Then you can just do [SHORTCODE_NAME] and whatever is in the SHORTCODE_NAME_shortcode() function will do its thing.

Passing variable in nested shortcodes

If I was going to be doing something like this, then I would actually build 2 shortcodes. One for the ‘boxes’ and one for the inside ‘box’. I do believe that is the only way plausable. When you build one for the outside box, just make sure to use do_shortcode(); around the content variable. If … Read more

Function shortcode – Set Parameter

There is a basic shortcode example in the Codex. function bartag_func( $atts ) { extract( shortcode_atts( array( ‘foo’ => ‘no foo’, ‘baz’ => ‘default baz’ ), $atts ) ); return “foo = {$foo}”; } add_shortcode( ‘bartag’, ‘bartag_func’ ); The array is the shortcode defaults and is used to fill in for any attribute that isn’t … Read more

Problem with height in video shortcode

It doesn’t seems to be a bug, but it’s designed like that only… Have a look how height variable is being changed by other parameter to keep up the right video ratio based on the theme. if ( ‘video’ === $type ) { $width = empty( $meta[‘width’] ) ? 640 : $meta[‘width’]; $height = empty( … Read more