• Resolved khanhvo

    (@whoiswho)


    Hi there,

    We are building a function to show post content in a popup modal (click a button to show the popup). But the Sassy_Social_Share shortcode returns empty.

    So could you please advice a way to show the social share buttons on this case?
    I checked the plugin code but there’s no attribute for post/post_ID.

    Waiting for your response!
    Regards,
    Khanh

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Heateor Support

    (@heateor)

    Hi,

    You can use the shortcode like this in the PHP code of the popup.
    <?php global $post; echo do_shortcode( '[Sassy_Social_Share url="' . get_permalink( $post->ID ) . '"]' ); ?>

    Thread Starter khanhvo

    (@whoiswho)

    Hi there,

    Thanks for your reply, but that doesn’t work. It still shows empty.

    I think this happens because it is checking the global post object in the callback function:
    global $post;
    if ( ! is_object( $post ) ) {
    return;
    }
    Can you please review?

    Thanks,
    Khanh

    Plugin Author Heateor Support

    (@heateor)

    I don’t know in which file you are placing the code and how that file is being used to trigger the popup. If you drop an email at support[at]heateor[dot]com, I would be able to check what’s wrong.

    Thread Starter khanhvo

    (@whoiswho)

    Hi, my code is placed in child theme functions.php, please review the code bellow. It just returns the title.

    add_action( ‘wp_ajax_ajax_kv_popup’, ‘ajax_kv_popup’ );
    add_action( ‘wp_ajax_nopriv_ajax_kv_popup’, ‘ajax_kv_popup’ );
    function ajax_kv_popup() {
    $post_id = $_POST[‘post_id’];
    $response = array(
    ‘html’ => ”,
    ‘success’ => true,
    );
    ob_start();
    echo ‘<div class=”modal_article_wrap”>’;

    echo ‘<h2 class=”postTitle”>’;
    echo ‘‘ . get_the_title($post_id) . ‘</h2>’;

    echo ‘<div class=”social_share_wrap”>’;
    echo do_shortcode(‘[Sassy_Social_Share title=”Share” align=”right” url=”‘.get_the_permalink($post_id).'”]’);
    echo ‘</div><!–.social_share_wrap–>’;

    echo ‘</div><!–.modal_article_wrap–>’;

    $response[‘html’] = ob_get_clean();
    echo json_encode( $response );
    die();
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Social Share in Ajax call’ is closed to new replies.