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)?

1
  • 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 Aug 26, 2015 at 20:59

1 Answer 1

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 ) );
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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