Skip to content

Instantly share code, notes, and snippets.

@gschoppe
Last active March 22, 2018 14:28
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 gschoppe/123ba7dec51ac653b9e6f8dfab3d35aa to your computer and use it in GitHub Desktop.
Save gschoppe/123ba7dec51ac653b9e6f8dfab3d35aa to your computer and use it in GitHub Desktop.
add to functions.php to allow WP jSlabify to slab post titles
<?php
add_filter( 'the_title', 'wp_jslabify_title', 10, 2 );
function wp_jslabify_title( $title, $id=0 ) {
$slabbed_post_types = array(
'single' => array( 'post', 'page' ),
'archive' => array(),
'search' => array()
);
$theme = 'ultra';
$ratio = 3;
$force = true;
$post_type = get_post_type( $id );
if( !is_main_query() || is_admin() ) {
return $title;
}
if( is_singular() ) {
if( !in_array( $post_type, $slabbed_post_types['single'] ) ) {
return $title;
}
} elseif( is_search() ) {
if( !in_array( $post_type, $slabbed_post_types['search'] ) ) {
return $title;
}
} else if( is_archive() ) {
if( !in_array( $post_type, $slabbed_post_types['archive'] ) ) {
return $title;
}
} else {
return $title;
}
if( $force ) {
$force = ' force="true"';
} else {
$force = '';
}
$shortcode = '[slab tag="span" theme="' . $theme . '" ratio="' . $ratio . '"'.$force.']' . $title . '[/slab]';
$title = do_shortcode( $shortcode );
return $title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment