Skip to content

Instantly share code, notes, and snippets.

@psaia
Created February 24, 2011 23:30
Show Gist options
  • Save psaia/843131 to your computer and use it in GitHub Desktop.
Save psaia/843131 to your computer and use it in GitHub Desktop.
A boilerplate functions file for WordPress
<?php
/**
* -- Configuration --
*
* Here you can add your javascript files, declare custom menus,
* add widgetized areas, and add custom post types. These variables
* are then processed inside the init() hook.
*
*/
// Include JavaScripts (to footer =)
$js = array(
'jquery' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js',
'FeedManager' => get_bloginfo('template_directory').'/assets/js/feedmanager.js',
'jquery_cycle' => get_bloginfo('template_directory').'/assets/js/jquery.cycle.all.min.js',
'jquery_fancybox' => get_bloginfo('template_directory').'/assets/js/jquery.fancybox-1.3.4.pack.js',
'application' => get_bloginfo('template_directory').'/assets/js/application.js',
);
// Declare Custom Menu Regions
$menus = array(
'main-nav' => 'Main Navigation',
'sub-nav' => 'Sub Navigation',
);
// Declare "Widgetized" Regions
$widgetized_regions = array(
array(
'name' => 'Right Sidebar',
'description' => 'The right sidebar.',
'before_title' => '<h2>',
'after_title' => '</h2>',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
),
/*
array(
'name' => '',
'description' => '',
'before_title' => '<h2>',
'after_title' => '</h2>',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
)
*/
);
// Declare Custom Post Types
// Refrence: http://codex.wordpress.org/Function_Reference/register_post_type
$post_types = array(
'some_type' => array(
'labels' => array('name' => 'Some Type'),
'public' => false,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 4,
'supports' => array('title','thumbnail','custom-fields')
),
/*
'another_type' => array(
'labels' => array('name' => 'Another Type'),
'public' => false,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 4,
'supports' => array('title','thumbnail','custom-fields')
),
*/
);
/**
* Add (what should be native) Support
*/
add_theme_support('menus');
add_theme_support('post-thumbnails');
/**
* Add sizes for thumbnails (if necessary)
*/
//set_post_thumbnail_size(128, 128, false); // default.. being set in CMS.. Settings -> Media
// add_image_size('featured_article', 200, 170, true);
/**
* Remove unnecessary meta boxes from the post edit form.
* Just to keep things clean.
*/
function fresh_admin_panel()
{
//Remove unnecessary meta boxes from the post edit form.
//Just to keep things clean.
/*
remove_meta_box('trackbacksdiv', 'post', 'normal');
remove_meta_box('authordiv', 'post', 'normal');
remove_meta_box('commentsdiv', 'post', 'normal');
remove_meta_box('commentstatusdiv', 'post', 'normal');
remove_meta_box('postexcerpt', 'post', 'normal');
remove_meta_box('commentsdiv', 'page', 'normal');
remove_meta_box('commentstatusdiv', 'page', 'normal');
remove_meta_box('postexcerpt', 'page', 'normal');
*/
}
/**
* Initialize
*/
function fresh_init()
{
// * Shouldn't need to touch this stuff * //
// Register JavaScripts
global $js;
if ( ! is_admin()) {
foreach ($js as $name => $path)
{
wp_deregister_script($name);
wp_register_script($name, $path, array(), false, true);
wp_enqueue_script($name, $path, array(), false, true);
}
}
// Menus
global $menus;
foreach ($menus as $machine => $human)
{
register_nav_menu($machine, $human);
}
// Custom Post Types
global $post_types;
foreach ($post_types as $name => $type)
{
register_post_type($name, $type);
}
// Register Sidebars
global $widgetized_regions;
foreach ($widgetized_regions as $region)
{
register_sidebar($region);
}
}
/**
* Hooks
*/
add_action('init', 'fresh_init');
add_action('admin_menu' , 'fresh_admin_panel');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment