WordPress functions file, the missing bits.

For a long time now I have had a bunch of core functions stored in my Coda snippets that I am always placing into the WordPress functions.php file in your theme.

I always start these days with BLANK Theme by Chris Coyer quite simply because it is the cleanest blank theme with no unnecessary code and these days as I am using WP for sites that are attracting a lot of traffic so code bloat and anything unnecessary causes me headache later, ..however this is not what this post is about, so I digress.

Below is my core functions.php file which I have now replaced the default one in BLANK-Theme with and it contains the following functionality:

  • remove ALL head links such as generator, rss, index_rel, parent_post, feed_links etc – although these can be useful for small blogs a large site does not always require them and if it does they usually manifest themselves in relevant areas of the content, so I save a number of function calls and also server load.
  • Load my own jQuery – So many plugins use jQuery and as those faithful followers of this post on loading jQuery in WordPress and its popularity will stand testament to, stopping everything else loading jQuery and taking control yourself is the way to go.
  • Add is_child() function – This is a crucial function I use a lot these days especially for corporate sites that have a complex hierarchal page structure and contextual sidebar menus, it simply allows you to check if the page is a child of a specified parent. This one should really be part of WP core.
  • Add Thumbnail support – This makes me raise my eyes to the ceiling every time I have to add it, I can’t believe WP has such useful technology with the ‘featured image’ and leave it turned off by default with no simple way to turn it on. To enable featured image you must edit the functions.php file!!
  • Expand the categories menu – When editing posts this makes the categories menu the full length to accomodate ALL of the categories being used, which from client feedback is much much more preferable than scrolling the tiny window you have currently.
<?php
	//remove all header links (comment out each line if you want it)
		remove_action( 'wp_head', 'feed_links' );
		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_generator');
 
	// Load jQuery as you want
		if ( !is_admin() ) {
		   wp_deregister_script('jquery');
		   wp_register_script('jquery', ("https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"), false, '1.5.1');
		   wp_enqueue_script('jquery');
		}
 
    // Function to check for if a page is in a specified hierachy
	    function is_child($post_id) {
			global $wp_query;
			$ancestors = $wp_query->post->ancestors;
			if(isset($ancestors)){
				if (in_array($post_id, $ancestors) ) {
					$return = true;
				} else {
					$return = false;
				} 
			} else {
				$return = false;
			}
			return $return;
		}
 
		//add thumbnails functionality
		add_theme_support( 'post-thumbnails' );
 
		//add expanding categories action and function
               add_action('admin_head', 'categories_selection_jquery');
 
					function categories_selection_jquery() {
						echo'
						<script type="text/javascript">
							jQuery(function($){
								$("#category-all.tabs-panel").height($("#categorychecklist").height());
							});
						</script>
						';
					}
 
 
    //and now back to the default wordpress sidebar registration, which although I do not use, I do not remove
    if (function_exists('register_sidebar')) {
    	register_sidebar(array(
    		'name' => 'Sidebar Widgets',
    		'id'   => 'sidebar-widgets',
    		'description'   => 'These are widgets for the sidebar.',
    		'before_widget' => '<div id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</div>',
    		'before_title'  => '<h2>',
    		'after_title'   => '</h2>'
    	));
    }
 
?>

Leave a comment

Subscribe Scroll to Top