Skip to content

Instantly share code, notes, and snippets.

@LucaRosaldi
Last active December 9, 2015 19:49
Show Gist options
  • Save LucaRosaldi/4319955 to your computer and use it in GitHub Desktop.
Save LucaRosaldi/4319955 to your computer and use it in GitHub Desktop.
WP: framework functions
<?php
/**
* Pretty Print (for debugging)
*
* @param mixed $val The value to print
*/
function pp($val = null) {
$ret = '<pre>';
if ( null === $val ) {
$ret .= 'null';
}
elseif ( false === $val ) {
$ret .= '(boolean) false';
}
elseif ( true === $val ) {
$ret .= '(boolean) true';
}
elseif ( is_array($val) || is_object($val) ) {
$ret .= print_r($val, true);
}
else {
$ret .= '('.gettype($val).') ' . htmlentities($val);
}
$ret .= '</pre>';
echo $ret;
}
/**
* Adds WP 3+ Functions & Theme Support
*/
function lr_theme_support() {
add_theme_support('post-thumbnails'); // wp thumbnails (sizes handled in functions.php)
set_post_thumbnail_size(150, 150, true); // default thumb size
add_custom_background(); // wp custom background
add_theme_support('automatic-feed-links'); // rss thingy
add_theme_support( 'post-formats', array('aside','gallery','image','link','quote','video','audio')); // post format support
// header image support: http://themble.com/support/adding-header-background-image-support/
}
add_action('after_setup_theme','lr_theme_support');
/**
* Removes unused menu items
*/
function lr_remove_menus() {
// remove_menu_page('tools.php'); // Tools page
// remove_menu_page('options-general.php'); // Settings page
}
// add_action( 'admin_menu', 'lr_remove_menus' );
/**
* Removes meta boxes on edit page in admin
*/
function lr_remove_page_fields() {
// remove_meta_box( 'postexcerpt' , 'post' , 'normal' ); //removes excerpt
// remove_meta_box( 'authordiv' , 'post' , 'normal' ); //removes author
}
// add_action( 'admin_menu' , 'lr_remove_page_fields' );
/**
* Cleans up unused widgets in admin dashboard
*/
function lr_remove_dashboard_widgets() {
remove_meta_box('dashboard_incoming_links', 'dashboard', 'core');
remove_meta_box('dashboard_plugins', 'dashboard', 'core');
remove_meta_box('dashboard_primary', 'dashboard', 'core');
remove_meta_box('dashboard_secondary', 'dashboard', 'core');
}
add_action( 'admin_menu', 'lr_remove_dashboard_widgets' );
/**
* Removes unnecessary columns in post list
*/
function lr_remove_columns( $defaults ) {
unset( $defaults['author'] );
return $defaults;
}
add_filter( 'manage_posts_columns', 'lr_remove_columns' );
add_filter( 'manage_pages_columns', 'lr_remove_columns' );
/**
* Cleans up WP <head>
*/
function lr_head_cleanup() {
// remove_action( 'wp_head', 'feed_links_extra', 3 ) // Category Feeds
// remove_action( 'wp_head', 'feed_links', 2 ) // Post and Comment Feeds
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'index_rel_link' );
remove_action( 'wp_head', 'parent_post_rel_link' );
remove_action( 'wp_head', 'start_post_rel_link' );
remove_action( 'wp_head', 'adjacent_posts_rel_link' );
remove_action( 'wp_head', 'wp_shortlink_wp_head' );
remove_action( 'wp_head', 'wp_generator' );
}
add_action('init', 'lr_head_cleanup');
/**
* Removes WP version from RSS
*/
add_filter('the_generator', '__return_empty_string');
/**
* Customizes excerpt more
*/
function lr_excerpt_more($more) {
return '&hellip;';
}
add_filter('excerpt_more', 'lr_excerpt_more');
/**
* Remove the p from around imgs
* (http://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/)
*/
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment