Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'wp_ajax_parse_shortcode_metabox', 'parse_shortcode_metabox' );
- add_action( 'wp_ajax_nopriv_parse_shortcode_metabox', 'parse_shortcode_metabox' );
- function parse_shortcode_metabox() {
- if( isset( $_POST ) ) {
- $shortcode = $_POST['shortcode'];
- echo do_shortcode( $shortcode );
- }
- die();
- }
- add_action( 'wp_footer', function() {
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function($) {
- // Find your button class
- $('.your-button-class').on('click', function(e) {
- e.preventDefault();
- var url = $(this).attr('href');
- var shortcode = url.substring(
- url.indexOf("=") + 1,
- );
- $.ajax({
- url: '<?php echo site_url() . '/wp-admin/admin-ajax.php'; ?>',
- type: 'POST',
- data: {
- 'shortcode': shortcode,
- 'action': 'parse_shortcode_metabox'
- },
- })
- .success(function(response) {
- // Redirect to URL with shortcode parsed value
- window.location.replace('http://your-site-url.com/?your_parameter=' + response);
- });
- })
- });
- </script>
- <?php
- }, 0 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement