Skip to content

Instantly share code, notes, and snippets.

@jartes
Last active March 6, 2019 08:16
Show Gist options
  • Save jartes/3b48168e221edce3a1be to your computer and use it in GitHub Desktop.
Save jartes/3b48168e221edce3a1be to your computer and use it in GitHub Desktop.
WordPress WPML has_category()
<?php
function has_wpml_category( $category_slug = null ) {
// bye bye no slug provided
if ( is_null( $category_slug ) )
return false;
// Default languange don't need to be checked
global $sitepress;
if ( ICL_LANGUAGE_CODE == $sitepress->get_default_language() )
return has_category( $category_slug );
// Multilingual category
$cat_object = get_category_by_slug( $category_slug );
$cat_id = $cat_object->term_id;
return has_category( icl_object_id( $cat_id, 'category', true );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment