Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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