Skip to content

Instantly share code, notes, and snippets.

@apathetic
Created November 24, 2012 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save apathetic/4138255 to your computer and use it in GitHub Desktop.
Save apathetic/4138255 to your computer and use it in GitHub Desktop.
Wordpress: general.php
<?php
/* --------------------------------
Enable/Disable WP stuff
------------------------------*/
// remove junk from head
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);
// add post thumbnail support + custom menu support
add_theme_support('post-thumbnails');
add_theme_support('nav-menus');
// remove unwanted core dashboard widgets
function rm_dashboard_widgets() {
global $wp_meta_boxes;
// unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); // right now [content, discussion, theme, etc]
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); // plugins
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); // incoming links
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); // wordpress blog
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); // other wordpress news
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); // quickpress
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']); // drafts
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); // comments
}
add_action('wp_dashboard_setup', 'rm_dashboard_widgets' );
// remove other dashboard widgets
global $sitepress;
remove_action('wp_dashboard_setup', array($sitepress, 'dashboard_widget_setup')); // WPML dashboard widget
// manage backend items
function manage_menu_items() {
remove_menu_page('link-manager.php');
}
add_action('admin_menu', 'manage_menu_items', 99);
// bitchin branding
function load_styles() {
echo '<style>#login{ padding-top:64px; } #login h1 a { background:url("'.get_bloginfo('template_url').'/images/logos/logo.png") 50% 50% no-repeat; height:112px; padding:0; }</style>'."\n";
}
add_action('login_head', 'load_styles');
// disable file editor
define('DISALLOW_FILE_EDIT',true);
/* --------------------------------
Misc
------------------------------*/
// Register our theme's menus
function register_menus() {
register_nav_menus(
array( 'main-menu' => __( 'Main Menu' ), 'footer-menu' => __( 'Footer Menu' ))
);
}
add_action( 'init', 'register_menus' );
// add "selected" class to parent menu item when on child page
function top_nav_classes( $current_classes, $item ) {
global $post;
$classes[] = ''; // notice how we make a brand-new array and don't use $current_classes
if( is_single() || is_404() || is_home() ) return $classes;
if (is_page() && $post->post_parent) { // we're on a sub-page
$parent = $post->post_parent;
if ($parent == get_post_meta($item->ID, '_menu_item_object_id', true)) { $classes[] .= 'selected'; }
} else {
if($post->ID == get_post_meta($item->ID, '_menu_item_object_id', true)) { $classes[] .= 'selected'; }
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'top_nav_classes', 10, 2 );
// simple, clean - single class on body
function clean_body_classes($classes, $class='') {
global $post;
if ( is_page() ){
$slug = ($post->post_parent) ? basename(get_permalink($post->post_parent)) : basename(get_permalink());
} else {
$slug = (is_archive()) ? '' : ''; // likely an archive page
}
$classes[] = $slug;
return $classes;
}
add_filter('body_class','clean_body_classes');
// make cleaner better permalink urls
function url_cleaner_clean($slug) {
// remove everything except letters, numbers and -
$pattern = '~([^a-z0-9\-])~i';
$replacement = '';
$slug = preg_replace($pattern, $replacement, $slug);
// when more than one - , replace it with one only
$pattern = '~\-\-+~';
$replacement = '-';
$slug = preg_replace($pattern, $replacement, $slug);
return $slug;
}
add_filter('editable_slug', 'url_cleaner_clean');
// facebook cruft
function facebook_cruft() { // facebook cruft
global $post;
if(is_single() || is_page()) :
while(have_posts()) : the_post();
$og_thumb_meta = get_post_meta($post->ID,'_thumbnail_id',false);
// $og_img = wp_get_attachment_image_src($og_thumb_meta[0], false);
$og_img = wp_get_attachment_image_src($og_thumb_meta, false);
$og_thumb = $og_img[0];
$og_excerpt = str_replace(array("\r\n", "\r", "\n"), "", get_the_excerpt());
$og_excerpt_clean = apply_filters('the_excerpt_rss', $og_excerpt);
endwhile;
echo '<meta property="og:title" content="'.get_bloginfo('name').' : '.single_post_title('', false).'" />'."\n";
echo '<meta property="og:description" content="'.strip_tags($og_excerpt_clean).'" />'."\n";
echo '<meta property="og:url" content="'.get_permalink($post->ID).'" />'."\n";
echo '<meta property="og:image" content="'.$og_thumb.'" />'."\n";
echo '<meta property="og:type" content="food" />'."\n";
else :
echo '<meta property="og:title" content="'.get_bloginfo('name').'" />'."\n";
echo '<meta property="og:description" content="'.get_bloginfo('description').'" />'."\n";
echo '<meta property="og:url" content="'.get_bloginfo('url').'" />'."\n";
echo '<meta property="og:image" content="'.get_bloginfo('template_url').'/images/logos/logo.png" />'."\n"; // [TODO] change or make sure this matches
echo '<meta property="og:type" content="website" />'."\n";
endif;
echo '<meta property="og:site_name" content="SITE TITLE HERE" />'."\n";
echo '<meta property="fb:admins" content="12345678" />'."\n";
}
add_action( 'wp_head', 'facebook_cruft', 5 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment