Skip to content

Instantly share code, notes, and snippets.

@jubalm
Created April 12, 2012 11:02
Show Gist options
  • Save jubalm/2366529 to your computer and use it in GitHub Desktop.
Save jubalm/2366529 to your computer and use it in GitHub Desktop.
Useful Wordpress Functions
<?php
// Useful Shortcodes
add_shortcode('home_url', 'return_home_url');
add_filter('widget_text', 'do_shortcode'); // enable shortcodes on widgets
function return_home_url() {
return home_url();
}
add_shortcode('theme_url', 'return_theme_url');
function return_theme_url() {
return get_bloginfo('template_url');
}
add_shortcode('uploads_url', 'return_uploads_url');
function return_uploads_url() {
$uploads_dir = wp_upload_dir();
return $uploads_dir['baseurl'];
}
// Register Sidebar
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h3>',
'after_title' => '</h3>',
'name' =>'My Widget Area'
'id' =>'widget-area'
));
}
// Add custom post type
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'home_slideshow',
array(
'labels' => array(
'name' => __( 'Posts' ),
'singular_name' => __( 'Post' )
),
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields' )
)
);
}
// Custom Wordpress Login Screen
add_filter( 'login_headerurl', 'login_page_url');
function login_page_url(){
return home_url();
}
add_filter( 'login_headertitle', 'login_page_title');
function login_page_title(){
return get_bloginfo('title', 'display' );
}
add_action('login_head', 'login_page_logo');
function login_page_logo()
{
echo '<link rel="stylesheet" href="' . get_bloginfo('template_directory') . '/login-style.css" />';
}
add_filter('login_message', 'login_page_text');
function login_page_text()
{
if(isset($_GET['reauth']))
{
return '<p class="message">You need to login to view this content</p>';
}
}
// Enqueue Styles and Scripts
add_action('wp_enqueue_scripts', 'load_style');
function load_style()
{
wp_enqueue_style( 'style', get_bloginfo() . '/css/style.css' );
wp_enqueue_script( 'script', get_bloginfo() . '/js/script.css', 'jquery', '1.0', true );
}
// Load Fancybox Dependencies with [gallery] shortcode
add_action('post_gallery', 'load_fancybox_dep');
function load_fancybox_dep()
{
wp_enqueue_style( 'fancybox', get_bloginfo('template_url') .'/css/jquery.fancybox-1.3.4.css' );
wp_enqueue_script( 'fancybox', get_bloginfo('template_url') .'/js/jquery.fancybox-1.3.4.pack.js', 'jquery', '1.3.4', true );
wp_enqueue_script( 'fancybox-settings', get_bloginfo('template_url') .'/js/fancybox-settings.js', 'fancybox', '1.0', true );
}
/*
* GRAVITY FORMS
**/
// Automatically Log User In After Registration
add_action("gform_user_registered", "autologin", 10, 4);
function autologin($user_id, $config, $entry, $password) {
$user_email = get_usermeta($user_id, 'user_email', true);
$result = wp_signon(array('user_login' => $user_email, 'user_password' => $password, 'remember' => false), true);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment