Skip to content

Instantly share code, notes, and snippets.

@Liroo
Last active June 16, 2019 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Liroo/d67051711a92720a9f8e54e15242ab38 to your computer and use it in GitHub Desktop.
Save Liroo/d67051711a92720a9f8e54e15242ab38 to your computer and use it in GitHub Desktop.
Find the best Barba namespace for your wordpress theme.
<?php
$barbaNamespace = '';
$post_type = get_post_type();
switch ($post_type) {
case 'page':
$barbaNamespace = get_query_var('pagename');
if ( !$barbaNamespace && $id > 0 ) {
// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
$post = $wp_query->get_queried_object();
$barbaNamespace = $post->post_name;
}
break;
// here I assume you have a CPT named project, it is my most common CPT name for portfolios
case 'project':
$barbaNamespace = 'project';
break;
default:
$barbaNamespace = 'default';
break;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment