This topic has 4 replies, 2 voices, and was last updated 9 years by sharmstr.

  • Author
  • #93123
     Matthias
    Participant

    Hi,

    I’m trying to create a shortcode for a follow button, I’m almost done but I still get an error when pasting to functions.php:

    // Add Shortcode

    function follow_shortcode() {

     

    $output ‘<div class=”um-followers-user-btn”>’;

     

    if ( $user_id1 == get_current_user_id() ) {

    echo ‘<a href=”‘ . um_edit_profile_url() . ‘” class=”um-follow-edit um-button um-alt”>’ . __(‘Edit profile’,’um-followers’) . ‘</a>’;

    } else {

    echo $um_followers->api->follow_button( $user_id1, get_current_user_id() );

    }

    $output'</div>’;

     

    }

     

    add_shortcode( ‘followBtn’, ‘follow_shortcode’ );

    Could you please take a minute to help me out on this ? I’m almost done but stuck.

    Thanks

    #93158
     sharmstr
    Moderator

    You code syntax is wrong.

    You should be doing “$output =” for both div lines and for the two lines that have echos. Then at the end you echo out $output

    COPY CODE
    
    echo $output;
    
    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #93160
     Matthias
    Participant

    Thank you very much for your help.
    I have this which still creates an error:

    COPY CODE
    function follow_shortcode() {
    
    $output = "<div class="um-followers-user-btn">
    		
    			if ( $user_id1 == get_current_user_id() ) {
    				echo '<a href="' . um_edit_profile_url() . '" class="um-follow-edit um-button um-alt">' . __('Edit profile','um-followers') . '</a>';
    			} else {
    				echo $um_followers->api->follow_button( $user_id1, get_current_user_id() );
    			}
    			
    </div>";
    
    echo $output;
    }
    add_shortcode( 'followBtn', 'follow_shortcode' );

    I followed what you said but it’s not working … Where did I go wrong ? Thanks for your help

    #93162
     sharmstr
    Moderator

    You didnt replace the 2 echo like I’ve instructed

    COPY CODE
    function follow_shortcode() {
    
        $output = '<div class="um-followers-user-btn">';
    		
    			if ( $user_id1 == get_current_user_id() ) {
    				$output .=  '<a href="' . um_edit_profile_url() . '">' . __('Edit profile','um-followers') . '</a>';
    			} else {
    				$output .=  $um_followers->api->follow_button( $user_id1, get_current_user_id() );
    			}
    			
    $ouptput .= '</div>';
     
    echo $output;
    }
    add_shortcode( 'followBtn', 'follow_shortcode' );
    
    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #93226
     sharmstr
    Moderator

    Did that work?

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

Viewing 5 posts - 1 through 5 (of 5 total)

The forum ‘General questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?