Skip to content

Instantly share code, notes, and snippets.

@arelthia
Created December 31, 2016 05:06
Show Gist options
  • Save arelthia/4d130b8871ed8a13cb4e68df0c6d82a7 to your computer and use it in GitHub Desktop.
Save arelthia/4d130b8871ed8a13cb4e68df0c6d82a7 to your computer and use it in GitHub Desktop.
Get WordPress CPT from front end
(function( $ ) {
'use strict';
var attrs, attr, postType;
postType = null;
$(function() {
// Look to see what type of post type we're working with
attrs = $( 'body' ).attr( 'class' ).split( ' ' );
$( attrs ).each(function() {
if ( 'post-type-' === this.substr( 0, 10 ) ) {
postType = this.split( 'post-type-' );
postType = postType[ postType.length - 1 ];
return;
}
});
});
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment