WordPress

Simple post counter

Someone in our WPSerbia FB Page asked about different styles for first post in the loop, so this is the snippet for that.   <?php if (have_posts()) : $counter = 1; while (have_posts()) : the_post(); if( $counter == 1 ) { ?> /* First post */ <? } elseif( $counter == 2 ) { ?> /* …

Simple post counter Read More »

Gravity forms, 18 years old verification

MM-DD-YYYY // this code will run for form 4 only; change 4 to your form ID add_filter(‘gform_validation_4’, ‘verify_minimum_age’); function verify_minimum_age($validation_result){ // retrieve the $form $form = $validation_result[‘form’]; // date of birth is submitted in field 7 in the format YYYY-MM-DD // change the 7 here to your field ID $dob = rgpost(‘input_7’); // this the …

Gravity forms, 18 years old verification Read More »

Twitter Bootstrap Drop-down on hover

Twitter Boostrap 3, drop-down menu on hover.   .dropdown-menu { .sub-menu { left: 100%; position: absolute; top: 0; visibility: hidden; margin-top: -1px; } li:hover .sub-menu { visibility: visible; } } .dropdown:hover .dropdown-menu { display: block; } .nav-tabs .dropdown-menu, .nav-pills .dropdown-menu, .navbar .dropdown-menu { margin-top: 0; } .navbar { .sub-menu:before { border-bottom: 7px solid transparent; border-left: …

Twitter Bootstrap Drop-down on hover Read More »

BuddyPress autologin on activation

add_action( “bp_core_activated_user”, “bp_autologin_on_activation”, 40, 3 ); function bp_autologin_on_activation( $user_id, $key, $user) { global $bp, $wpdb; //simulate Bp activation /* Check for an uploaded avatar and move that to the correct user folder, just do what bp does */ if ( is_multisite() ) $hashed_key = wp_hash( $key ); else $hashed_key = wp_hash( $user_id ); /* Check …

BuddyPress autologin on activation Read More »

You May Also Like, filter snippet

“You May Also Like”, code snippet for displaying list of posts from the same category on page: add_filter( ‘the_content’, function() { $id = get_the_id(); if ( !is_singular( ‘post’ ) ) { return $content; } $terms = get_the_terms( $id, ‘category’ ); $cats = array(); foreach ($terms as $term) { $cats[] = $term->cat_ID; } $loop = new …

You May Also Like, filter snippet Read More »

Trim posts with status future like post status publish

// Trim posts with status future like post status publish function custom_archive_query($query) { if ( $query->is_archive() ) { $query->set(‘post_status’, array(‘future’, ‘publish’)); } return $query; } add_filter(‘pre_get_posts’, ‘custom_archive_query’); Source: 10+ Useful WordPress Code Snippets

Trim AJAX Calendar Future POSTS to be valid

// Trim AJAX Calendar Future POSTS to be valid add_filter(‘get_calendar’, ‘customize_calendar_output’); function customize_calendar_output($calendar_output) { $calendar_output = str_replace(‘<table id=”wp-calendar” summary=”‘ . esc_attr__(‘Calendar’) . ‘”>’, ‘<table id=”wp-calendar”>’, $calendar_output); return $calendar_output; } Source: 10+ Useful WordPress Code Snippets

Add new dashboard widget

// Add new dashboard widget function new_dash_widget_function() { ?> <p>Some text or Html.</p> <?php } function add_dashboard_widgets() { wp_add_dashboard_widget(‘new_dash_widget’, ‘Your_Widget_name’, ‘new_dash_widget_function’); } add_action(‘wp_dashboard_setup’, ‘add_dashboard_widgets’); Source: 10+ Useful WordPress Code Snippets

Remove Posts menu for Editor, Author, and Contributor

// Remove Posts menu for Editor, Author, and Contributor if (! current_user_can(‘manage_options’)) { add_action(‘admin_menu’, ‘notadmin_remove_menus’, 999); function notadmin_remove_menus() { remove_menu_page(‘edit.php’); // Posts remove_menu_page(‘tools.php’); // Tools remove_submenu_page(‘edit.php?post_type=custom_post_type’, ‘post-new.php?post_type=custom_post_type’); // Custom Post Type } } Source: 10+ Useful WordPress Code Snippets

Remove Items from admin bar for authors

// Remove Items from admin bar for authors function remove_admin_bar_links() { if (current_user_can(‘author’)){ global $wp_admin_bar; $wp_admin_bar->remove_menu(‘new-content’); // Remove Add New $wp_admin_bar->remove_menu(‘comments’); // Remove Comments $wp_admin_bar->remove_menu(‘wpseo-menu’); // Remove Yoast SEO links menu $wp_admin_bar->remove_menu(‘documentation’); // Remove the WordPress documentation link $wp_admin_bar->remove_menu(‘support-forums’); // Remove the support forums link $wp_admin_bar->remove_menu(‘feedback’); // Remove the feedback link } } add_action(‘wp_before_admin_bar_render’, ‘remove_admin_bar_links’); …

Remove Items from admin bar for authors Read More »

Scroll to Top