Last active
May 1, 2018 09:38
-
-
Save ThomasLarge/7c749fc0afdd2b6b1ea1a55e063c21ca to your computer and use it in GitHub Desktop.
WP Standard Functions
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
// Add SVG to media libary upload | |
function cc_mime_types($mimes) { | |
$mimes['svg'] = 'image/svg+xml'; | |
return $mimes; | |
} | |
add_filter('upload_mimes', 'cc_mime_types'); |
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
// Redirect all users but admin to home page | |
add_action( 'admin_init', 'redirect_non_admin_users' ); | |
function redirect_non_admin_users() { | |
if ( ! current_user_can( 'manage_options' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) { | |
wp_redirect( home_url() ); | |
exit; | |
} | |
} |
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
// Custom footer text | |
function remove_footer_admin () { | |
echo '<span id="footer-thankyou">Developed by <a href="http://www.rawww.com" target="_blank">Rawww</a></span>.'; | |
} | |
add_filter('admin_footer_text', 'remove_footer_admin'); |
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
// Exclude a Category from Search Results | |
add_filter( 'pre_get_posts' , 'search_exc_cats' ); | |
function search_exc_cats( $query ) { | |
if( $query->is_admin ) | |
return $query; | |
if( $query->is_search ) { | |
$query->set( 'category__not_in' , array( 30 ) ); // Cat ID | |
} | |
return $query; | |
} |
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
// mod expert | |
function excerpt($limit) { | |
$excerpt = explode(' ', get_the_excerpt(), $limit); | |
if (count($excerpt)>=$limit) { | |
array_pop($excerpt); | |
$excerpt = implode(" ",$excerpt).'...'; | |
} else { | |
$excerpt = implode(" ",$excerpt); | |
} | |
$excerpt = preg_replace('`[[^]]*]`','',$excerpt); | |
return $excerpt; | |
} | |
function content($limit) { | |
$content = explode(' ', get_the_content(), $limit); | |
if (count($content)>=$limit) { | |
array_pop($content); | |
$content = implode(" ",$content).'...'; | |
} else { | |
$content = implode(" ",$content); | |
} | |
$content = preg_replace('/[.+]/','', $content); | |
$content = apply_filters('the_content', $content); | |
$content = str_replace(']]>', ']]>', $content); | |
return $content; | |
} | |
// Use this in template - <?php echo excerpt('number of words');?> |
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
// Disable WP responsive images | |
function meks_disable_srcset( $sources ) { | |
return false; | |
} | |
add_filter( 'wp_calculate_image_srcset', 'meks_disable_srcset' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment