0

Let's say I have a page, and inside that page, I have inserted shortcodes/plugins for a chatbox, twitter feeds, fb feeds, tumblr, etc. The shortcode accepts parameters for different hashtags to display, links, keywords,

What I want to achieve in my page is that there are text that when clicked, it will fetch the latest content from that hashtags. For example, if the user click 'Tove Lo', the parameters in the shortcode will be changed to 'Tove Lo', and it will refresh that. How can we make a shortcode/plugin refresh in a that page (while passing the text value to the shortcode so that it will fetch that content)?

  • I was thinking of jQuery/AJAX to do this.. But how can I make jQuery/AJAX insert the modifications in the shortcode, and then reload it? Thank you – WantIt Aug 26 '15 at 20:59
4

If you want to do this via AJAX, on the server side you could do something like the following:

add_action( 'wp_ajax_nopriv_update_shortcode_content', 'update_shortcode_content' );

function update_shortcode_content(){
    if( !empty( $_GET['new_shortcode_value'] ) ){
        $updated_content = do_shortcode( '[theshortcode value="' . $_GET['new_shortcode_value'] . '"]' );
        wp_send_json( array( "content" => $updated_content ) );
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.