Skip to content

Instantly share code, notes, and snippets.

View robgolbeck's full-sized avatar

Rob Golbeck robgolbeck

View GitHub Profile
@robgolbeck
robgolbeck / x-nav-button-remove-shadow
Created December 6, 2015 08:36
X Theme Snippets: Remove shadow from mobile nav button.
/* remove box shadow from mobile nav button */
a.x-btn-navbar,
a.x-btn-navbar.collapsed,
a.x-btn-navbar.collapsed:hover {
box-shadow: none;
}
@robgolbeck
robgolbeck / x-custom-header-navbar.php
Last active November 15, 2015 22:53
Custom Header Template for X Theme
<?php
// =============================================================================
// Outputs the child theme navbar.
//
// Step 1: Replicate _navbar.php to your child theme
// Notes:
// a) Path must match the path in parent theme: framework/views/global/_navbar.php
// b) Set logo and navigation layout to 'Stacked' in Appearance > Customizer > Header
// c) Wrap logo and content area in separate containers, to facilitate styling.
@robgolbeck
robgolbeck / Enable Relvanssi search plugin to index custom fields
Created May 14, 2015 23:57
Enable Relvanssi search plugin to index custom fields
<?php
// Use this if you need the Relevanssi advanced search plugin to index content in custom fields.
add_filter('relevanssi_excerpt_content', 'excerpt_function', 10, 3);
function excerpt_function($content, $post, $query) {
global $wpdb;
$fields = $wpdb->get_col("SELECT DISTINCT(meta_key) FROM $wpdb->postmeta");
foreach($fields as $key => $field){
$field_value = get_post_meta($post->ID, $field, TRUE);
$content .= ' ' . ( is_array($field_value) ? implode(' ', $field_value) : $field_value );
@robgolbeck
robgolbeck / Show content from one page on another page
Last active August 29, 2015 14:21
Show content from one page on another page
<?php
// Add this to functions.php
function hc_show_content($path) {
$post = get_page_by_path($path);
$content = apply_filters('the_content', $post->post_content);
echo $content;
}
?>
@robgolbeck
robgolbeck / Remove Unnecessary Sidebar Widgets
Last active June 11, 2017 09:47
Remove Unnecessary Sidebar Widgets
<?php
// Remove unnecessary sidebar widgets that will never be used in the theme.
// Reference: https://codex.wordpress.org/Function_Reference/unregister_widget
function hc_widgets_init() {
unregister_widget( 'WP_Widget_Pages' );
unregister_widget( 'WP_Widget_Calendar' );
unregister_widget( 'WP_Widget_Archives' );
unregister_widget( 'WP_Widget_Links' );
unregister_widget( 'WP_Widget_Meta' );
unregister_widget( 'WP_Widget_Search' );
@robgolbeck
robgolbeck / WordPress Sample Theme Customizer
Last active April 28, 2017 21:46
WordPress Sample Theme Customizer
<?php
// Sample Theme Customizer Options for WordPress
// This example allows you to upload your logo, add your contact info, and add your social media links.
// Reference: https://codex.wordpress.org/Theme_Customization_API
// See also: http://themefoundation.com/wordpress-theme-customizer/
// Add the following to functions.php (or put it in a separate file - e.g. theme-customizer.php - and call it from functions.php)
new theme_customizer();
class theme_customizer
@robgolbeck
robgolbeck / WordPress Reorder Admin Menu
Last active August 29, 2015 14:19
Function to change the order of the admin menu items in WordPress.
<?php
// Rearrange the admin menu
// Reference: https://codex.wordpress.org/Plugin_API/Filter_Reference/custom_menu_order
function custom_menu_order($menu_ord) {
if (!$menu_ord) return true;
return array(
'index.php', // Dashboard
'edit.php?post_type=page', // Pages
'edit.php?post_type=YOUR-CUSTOM-POST-TYPE', // Custom Post Type
'edit.php', // Blog Posts
@robgolbeck
robgolbeck / WordPress Remove Items from Admin Menu
Last active August 29, 2015 14:19
Function to remove unused items from the WordPress admin menu
<?php
// Remove unused items from the admin menu
// Reference: https://codex.wordpress.org/Function_Reference/remove_menu_page
function remove_menus(){
remove_menu_page( 'edit.php' ); // Posts
remove_menu_page( 'edit-comments.php' ); //Comments
}
add_action( 'admin_menu', 'remove_menus' );
?>
@robgolbeck
robgolbeck / WordPress Customize User Role
Last active August 29, 2015 14:19
WordPress Custom User Role
<?php
// Assign custom permissions for specific user roles
// This example gives Editors access to Menus and Theme Options:
add_action( 'admin_menu', 'edit_admin_menus' );
// Allow editors to manage theme options (under Appearance)
$role_object = get_role( 'editor' );
$role_object->add_cap( 'edit_theme_options' );
@robgolbeck
robgolbeck / WordPress Add Custom Dashboard Widgets and Hide Unnecessary Ones
Last active August 29, 2015 14:10
WordPress Add Custom Dashboard Widgets and Hide Unnecessary Ones
<?php
// Add Custom Dashboard Widgets
// This example adds a 'welcome' message to the dashboard.
'
add_action('wp_dashboard_setup', 'sw_custom_dashboard_widgets');
function sw_custom_dashboard_widgets() {
global $wp_meta_boxes;
$normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
$sw_widget_backup = array( 'sw_custom_dashboard_widgets' => $normal_dashboard['sw_custom_dashboard_widgets'] );
unset( $normal_dashboard['sw_custom_dashboard_widgets'] );