Skip to content

Instantly share code, notes, and snippets.

@ThomasLarge
Last active May 1, 2018 09:38
Show Gist options
  • Save ThomasLarge/7c749fc0afdd2b6b1ea1a55e063c21ca to your computer and use it in GitHub Desktop.
Save ThomasLarge/7c749fc0afdd2b6b1ea1a55e063c21ca to your computer and use it in GitHub Desktop.
WP Standard Functions
// 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');
// 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;
}
}
// 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');
// 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;
}
// 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(']]>', ']]&gt;', $content);
return $content;
}
// Use this in template - <?php echo excerpt('number of words');?>
// 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