Skip to content

Instantly share code, notes, and snippets.

@verygoodplugins
Last active December 14, 2023 13:22
Show Gist options
  • Save verygoodplugins/2dd9464fa22bde8f36f3d1863890bd2f to your computer and use it in GitHub Desktop.
Save verygoodplugins/2dd9464fa22bde8f36f3d1863890bd2f to your computer and use it in GitHub Desktop.
Add tags as classes to the body
<?php
// Adds a current logged in users tags to the <body> element's classes.
function wpf_tags_body_class( $classes ) {
if ( ! function_exists( 'wp_fusion' ) ) {
return $classes;
}
if( ! wpf_is_user_logged_in() || wpf_admin_override() ) {
return $classes;
}
$tags = wp_fusion()->user->get_tags();
if( ! empty( $tags ) ) {
foreach( $tags as $tag_id ) {
$tag_name = sanitize_title( wp_fusion()->user->get_tag_label( $tag_id ) );
$classes[] = 'tag-' . $tag_name;
}
}
return $classes;
}
add_filter( 'body_class', 'wpf_tags_body_class' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment