Plugins & Themes

Add Code Under Custom Taxonomy Description

4 Replies ·

  1. This query has two parts.

    1. How can I add code under the custom taxonomy description?

    The second is a bit more complicated.

    1. The code I want to add is javascript from Amazon which includes the following line:
    amzn_assoc_default_search_phrase = "SEARCH TERM";

    I want the search term to be the custom taxonomy term which I know can be pulled from the page using php because I have done it before (but I don’t remember how).

    The question is can I use the php code inside the javascript code to do this?

    Here is an example of a custom taxonomy with the code manually inserted. There are over 10,000 custom taxonomies so this would be a huge time saver.

    Any help would be appreciated.

  2. Justin Tadlock

    I assume you mean “term description” rather than “taxonomy description”. 🙂

    Are you listing the terms on a specific page? Or, are you referring to something like the taxonomy term archive page?

  3. Justin Tadlock

    In your theme template that outputs the term description (depends on your theme where this is output), you’ll need something like this:

    <?php if ( is_tax() || is_category() || is_tag() ) : ?>
        <?php $term = get_queried_object(); ?>
        amzn_assoc_default_search_phrase = "<?php echo esc_js( $term->slug ); ?>";
    <?php endif; ?>

    You can use $term->name instead of $term->slug in the code above if you prefer the name.