How To Register A Sidebar In function.php
The following snippet will let you register a sidebar in function.php.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
/* register sidebars */ if ( function_exists('register_sidebar') ){ register_sidebar(array('name' => 'Sidebar', 'before_widget' => '<li class=wpSidebar >', 'after_widget' => '</li>', 'before_title' => '<h3>', 'after_title' => '</h3>', )); register_sidebar(array('name' => 'Footer', 'before_widget' => '<li class=wpFooterSidebar >', 'after_widget' => '</li>', 'before_title' => '<h3>', 'after_title' => '</h3>', )); } |
Snippet Source/Credit: Snipplr
How To Register A Widget In function.php
The following snippet will let you register a widget in function.php.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
add_action("widgets_init", array('Widget_name', 'register')); class Widget_name { function control(){ echo 'I am a control panel'; } function widget($args){ echo $args['before_widget']; echo $args['before_title'] . 'Your widget title' . $args['after_title']; echo 'I am your widget'; echo $args['after_widget']; } function register(){ register_sidebar_widget('Widget name', array('Widget_name', 'widget')); register_widget_control('Widget name', array('Widget_name', 'control')); } } |
Snippet Source/Credit: Snipplr
How To Register Any Number Of WordPress Custom Menu Locations
Using the following snippet, you will be able to register any number of WordPress custom menu locations.
1 2 3 4 |
if(function_exists('register_nav_menus')) { register_nav_menus(array('main-menu' => 'Main Menu','footer-menu' => 'Footer Menu')); } |
Snippet Source/Credit: DarrenHuskie.com
How To Remove Code Which Got Added For An iframe Injection In WordPress
The following snippet will let you remove the code which got added for an iframe injection. Before doing this, make sure you do backup all your data.
1 2 3 4 |
# FIND find . -type f | xargs grep -l '<iframe.*statanalyze.cn.*iframe' # REPLACE find . -type f -exec sed -i 's/<iframe.*statanalyze.cn.*iframe>//g' {} \; |
Snippet Source/Credit: WordPress.org
How To Remove Dashboard Widgets In WordPress
The following snippet will let you remove the dashboard widgets in your WordPress website. Paste the following into your functions.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function remove_dashboard_widgets() { global $wp_meta_boxes; unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_drafts']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); } if (!current_user_can('manage_options')) { add_action('wp_dashboard_setup', 'remove_dashboard_widgets' ); } |
Snippet Source/Credit: WPRecipes.com