Last active
March 22, 2018 14:28
-
-
Save gschoppe/123ba7dec51ac653b9e6f8dfab3d35aa to your computer and use it in GitHub Desktop.
add to functions.php to allow WP jSlabify to slab post titles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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