Skip to content

Instantly share code, notes, and snippets.

@fueledbyboredom
fueledbyboredom / custom-excerpt-length.php
Created February 14, 2017 16:41
Customize the length of excerpts, in this example we are returning 20 words
<?php
function mwpf_custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'mwpf_custom_excerpt_length');
@fueledbyboredom
fueledbyboredom / remove-admin-bar.php
Created February 14, 2017 16:35
Disables the front-end admin bar.
<?php
add_filter( 'show_admin_bar', '__return_false' );
@fueledbyboredom
fueledbyboredom / google-html5-shim.php
Created February 14, 2017 16:24
Use Google's version of the HTML5 shim for older versions of Internet Explorer
<?php
function mwpf_IEhtml5_shim () {
global $is_IE;
if ($is_IE)
echo '<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->';
}
add_action('wp_head', 'mwpf_IEhtml5_shim');
@fueledbyboredom
fueledbyboredom / disable-admin-editor.php
Created February 14, 2017 16:20
Disable the theme editor that is available from the WordPress admin dashboard.
<?php
define('DISALLOW_FILE_EDIT', true);
@fueledbyboredom
fueledbyboredom / remove-header-version.php
Created February 14, 2017 16:19
This will remove the WordPress version number from the header, this information is also available in the "readme.html" file in the root of the WordPress directory, so it would be a good idea to remove that file as well.
<?php
remove_action('wp_head', 'wp_generator');
@fueledbyboredom
fueledbyboredom / oembed-maximum-width.php
Created February 14, 2017 16:16
Sets a maximum width for content that is loaded in via an oembed
<?php
if ( ! isset( $content_width ) )
$content_width = 660;
@fueledbyboredom
fueledbyboredom / remove-p-tags.php
Created February 14, 2017 16:14
Strip <p> tags from images that are outputted via the_content().
<?php
function mwpf_remove_img_ptags($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'mwpf_remove_img_ptags');
@fueledbyboredom
fueledbyboredom / more-search-results.php
Created February 14, 2017 16:06
Get more search results per page, in this example it is set to return 25 per page.
<?php
function mwpf_search_results_per_page( $query ) {
global $wp_the_query;
if ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_search() ) ) {
$query->set( 'mwpf_search_results_per_page', 25 );
}
return $query;
}
add_action( 'pre_get_posts', 'mwpf_search_results_per_page' );
@fueledbyboredom
fueledbyboredom / customize-admin-footer.php
Last active February 14, 2017 16:05
Allows you to edit the content in the footer of the admin dashboard.
@fueledbyboredom
fueledbyboredom / obscure-login-errors.php
Last active February 14, 2017 16:05
Obscure WordPress Login Error Messages
<?php
function mwpf_login_obscure(){ return '<strong>Sorry</strong>: Think you have gone wrong somwhere!';}
add_filter( 'login_errors', 'mwpf_login_obscure' );