• Resolved stipto

    (@stipto)


    Hey there,

    I love this plugin! Love how the buttons work out. Really nicely done.
    Now, I’m no php programmer so I must be doing something wrong here. I have a comparison plugin installed and would like to show the button from Shortcode Ultimate instead of the standard “Read the review” link.
    Now, in the php file of the comparison there is the following line, displaying the link:

    if (!($settings & MYRP_VC_REVIEW)) {
    		$return .= "<a href='" . get_permalink($post_id) . "' class='myrp_review_link'>" . myrp_i18n("Review") . "</a>";
    	}

    Now I thought, if it spits out an \<a\> element, it could probably spit out a shortcode button. So I added it like this:

    if (!($settings & MYRP_VC_REVIEW)) {
     $return .= "[button link='" . get_permalink($post_id) . "' color="#0086bf" size="1" style="1" dark="0" square="0"]" . myrp_i18n("Review") . "[/button]";
    	}

    But it doesn’t work. Anyone know how to do this ideally? Should I use the function instead of the shortcode?

    Cheers!

Viewing 15 replies - 1 through 15 (of 15 total)
  • Hi stipto!

    Wrap you shortcode into special WordPress function do_shortcode()

    In PHP code

    before:
    $return = ‘[button link=”‘ . get_permalink( $post_id ) . ‘”] Hi there! [/button]’;

    after:
    $return = do_shortcode( ‘[button link=”‘ . get_permalink( $post_id ) . ‘”] Hi there! [/button]’ );

    Or just:

    before:

    $return = '[button link="' . get_permalink( $post_id ) . '"] Hi there! [/button]';

    after:

    $return = '[button link="' . get_permalink( $post_id ) . '"] Hi there! [/button]';
    do_shortcode( $return );

    Thread Starter stipto

    (@stipto)

    Thanks!! Works like a charm!!

    Or =)
    you can use my native function

    gn_button_shortcode(
       array(
          'link' => 'https://example.com/',
          'color' => '#fc0'
       ), 'Button text'
    );

    But I’m recommend you use a do_shortcode() function

    Not at all =)

    Thread Starter stipto

    (@stipto)

    I’ve got one more! Here goes:
    Replace the following with a shortcode button:

    if ($visit_site != "") {
    		$return .= "<strong><a href='{$visit_site}'";
        	if (get_option("myrp_embed_visit_site_nofollow") == 1)
        	$return .= " rel='nofollow'";
        	if (($options & MYRP_VC_NEWWINDOW))
        	$return .= " target='_blank'";
      		$return .= " >{$link_text}</a></strong>";
       		}

    This one’s difficult, because I think the variable $visit_site won’t work inside the shortcode.

    Try second method

    do_shortcode( $return );

    if will not work, then i can’t help

    Thread Starter stipto

    (@stipto)

    I’ve got it like this, but the variable doesn’t get read (probably I wrote wrong php):

    if ($visit_site != "") {
    
    $return = '[button link="'.$visit_site.'"] Hi there! [/button]';
    do_shortcode( $return );
    
       		}

    It’s right code, but you forget to print result =)

    if ( $visit_site ) {
    	$return = '[button link="' . $visit_site . '"] Hi there! [/button]';
    	echo do_shortcode( $return );
    }

    Function do_shortcode() don’t print variable, it just processes them

    Thread Starter stipto

    (@stipto)

    Great, thanks! The buttons get printed now except for the last one, and my whole layout is messed up. But I’m getting there ??

    Don’t forget to share link to plugin =)

    Thread Starter stipto

    (@stipto)

    What do you mean, to your plugin?

    It mean if you want to support author (me), share link to this plugin in twitter or any social network. Link – https://ilovecode.ru/?p=122

    Thanks in advance =)

    Thread Starter stipto

    (@stipto)

    Of course man! Thanks for the great work.

    Thanks for using it =)

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘[Plugin: Shortcodes Ultimate] Using shortcode in another plugin’ is closed to new replies.