Skip to content

Instantly share code, notes, and snippets.

@intelliweb
intelliweb / hide_admin_bar.php
Created June 11, 2014 19:25
WP: remove/hide the WP admin bar for all users who cannot edit posts
<?php
// Remove WP admin bar for all users who can’t edit posts
add_action('set_current_user', 'intw_hide_admin_bar');
function intw_hide_admin_bar() {
if (!current_user_can('edit_posts')) {
show_admin_bar(false);
}
}
@intelliweb
intelliweb / custom_string_length.php
Created August 8, 2014 20:43
WP: Custom length for content, excerpt, title, etc. using WP's wp_trim_words function
<?php
/* Trim content, excerpt, or any other string of text to a specified number of words */
wp_trim_words( $text, $num_words = 55, $more = '...' );
/* Custom function to trim the title. Use in place of get_the_title()
Example usage showing max 10 words of the title: <?php echo intw_trim_title(10); ?> */
function intw_trim_title($n) {
return wp_trim_words( get_the_title(), $n );
}
@intelliweb
intelliweb / disable_admin_bar_search.php
Created October 2, 2014 15:18
WP: The search form in the admin bar can cause a security warning over HTTPS (SSL). This snippet disables the search form in the admin bar.
<?php
// Disable search icon and input in admin bar
add_action( 'wp_before_admin_bar_render', 'intw_disable_admin_bar_search' );
function intw_disable_admin_bar_search() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('search');
}
@intelliweb
intelliweb / remove_gf_admin_menu.php
Created December 12, 2014 03:45
GF: Remove admin menu item by user capability. Be sure to add custom capability first!
<?php
// Be sure to add custom capability first!
// Remove GF menu for anyone not having custom capability
add_action('admin_menu', 'intw_remove_gf_menus', 999);
function intw_remove_gf_menus() {
if( !current_user_can('gravityforms_full_access') ) {
remove_menu_page( 'gf_edit_forms' );
}
}
@intelliweb
intelliweb / logout_link_shortcode.php
Last active December 11, 2015 22:09
Custom shortcode to add logout link with optional redirect URL and link text attributes
@intelliweb
intelliweb / user_meta_shortcode.php
Created January 29, 2013 21:28
Custom shortcode to display user meta for currently logged in user
<?php
// Custom shortcode to display user meta for currently logged in user
add_shortcode('intw_user_meta', 'intw_user_meta_func');
function intw_user_meta_func($atts) {
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
$content = '<p>Welcome, ' . $current_user->display_name . '!</p>';
return $content;
}
@intelliweb
intelliweb / WP Headway: custom header and footer
Created January 29, 2013 21:34
Custom header and footer in Headway 2.x
@intelliweb
intelliweb / builder_nav_style_to_menu.php
Last active December 14, 2015 21:39
Builder: Add navigation module styling to custom nav menu
<?php
/********************************************
Add the following to functions.php
********************************************/
// Register custom nav menu locations
register_nav_menus( array(
'main_nav' => 'Main Navigation Menu',
'footer_menu' => 'Footer Menu'
) );
@intelliweb
intelliweb / builder_custom_module_css_class.php
Created March 14, 2013 19:32
Builder: Add custom CSS class names to Builder modules
<?php
// Custom Builder module CSS classes for styling
if ( ! function_exists( 'it_builder_loaded' ) ) {
add_action( 'it_libraries_loaded', 'it_builder_loaded' );
function it_builder_loaded() {
builder_register_module_style( array('html','widget-bar','content'), 'Sample Style Name', 'sample-style-class' );
}
}
@intelliweb
intelliweb / before_after_body.php
Created March 21, 2013 02:05
Builder: Add code just after <body> and just before </body>
<?php
// Hook right after opening <body> tag
add_action('builder_layout_engine_render_header', 'intw_add_after_opening_body', 20 );
function intw_add_after_opening_body() { ?>
HTML code that you want just after the opening body tag should be placed here
<?php }
// Hook right before closing </body> tag
add_action('builder_finish', 'intw_add_before_closing_body', 0 );
function intw_add_before_closing_body() { ?>