0

I am trying to add a script for an affiliate widget into the back end of my website so I can use a custom taxonomy for the variable.

Basically below where the script asks for destination I would like to add the name of the current destination. Destination is a custom taxonomy on my wordpress site.

<script async defer src="//widget.getyourguide.com/v2/core.js" 
onload="GYG.Widget(document.getElementById('gyg-widget- 
5b2dae9ec139c4.60431654'),{'currency':'USD','localeCode':'en- 
US','numberOfItems':'3','partnerId':'XXXXXX','q':'DESTINATION'});"></script>

I have tried $destname = single_cat_title(); and then using echo ($destname) inside the script but it doesnt seem to work.

Any ideas Richard

0

I think you should use json_encode in the page that you would like to run. Here is some ideas how you to solves.

add_action('admin_init', 'my_taxonomy_list');
function my_taxonomy_list() {
  if (specific_page) { //check not to run in other pages
        $taxonomies = get_taxonomies(); 
        foreach ( $taxonomies as $taxonomy ) {
            $tax_list[] = $taxonomy->slug;
        }
    ?>
    <script>
        var tax_list = <?php echo json_encode( $tax_list ) ?>;
    </script>
    <?php
  }
}

And then you could access tax_list to be able to use in javascript file.

| improve this answer | |

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.