Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress: Changing Stylesheets depending on Custom Taxonomy Terms

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #35602
    kathemo
    Member

    Worked something out! Here’s the code I used via WordPress’s is_tax function:

    add_filter( 'stylesheet_uri', 'my_stylesheet', 10, 2 );

    function my_stylesheet( $stylesheet_uri, $stylesheet_dir_uri ) {

    if ( is_tax( 'grades', array('term_name' => 'Kindergarten', 'First Grade', 'Second Grade', 'Third Grade', 'Fourth Grade', 'Fifth Grade' ) ))
    $stylesheet_uri = $stylesheet_dir_uri . '/style-elemen.css';
    elseif ( is_tax( 'grades', array('term_name' => 'Sixth Grade', 'Seventh Grade', 'Eighth Grade' ) ))
    $stylesheet_uri = $stylesheet_dir_uri . '/style-elemen.css';

    return $stylesheet_uri;
    }

    My client would like the background & header colors to switch depending on three subsets of the custom taxonomy ‘Grades’ (K+elementary, middle & high school)

    I’ve registered and set up the custom taxonomy ‘grades’ but I can’t figure out how to load the different stylesheet depending on the taxonomy terms.

    I found a great blogpost regarding contextually changing the stylesheet depending on the page name ( http://justintadlock.com/archives/2009/07/27/contextually-changing-your-themes-stylesheet ). My php understanding is a bit limited and I can’t figure out how to call the custom taxonomy with an array of terms.

    tl;dr – It looks like taxonomy_exists is what I should use but that only calls the custom taxonomy. I’d like to call the custom taxonomy ‘grades’ with an array of terms ‘kindergarten’ ‘first-grade’ ‘second-grade’ and such to trigger a change in the stylesheet.

    #92538
    TheDoc
    Member
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.