Loading...

Follow Code And Me - WordPress Code Snippet Repository on Feedspot

Continue with Google
Continue with Facebook
or

Valid

Using the following snippet will let you get next and previous posts by alphabetical order.

function filter_next_post_sort($sort) {
  $sort = "ORDER BY p.post_title ASC LIMIT 1";
  return $sort;
}
function filter_next_post_where($where) {
  global $post, $wpdb;
  return $wpdb->prepare("WHERE p.post_title > '%s' AND p.post_type = 'post' AND p.post_status = 'publish'",$post->post_title);
}
function filter_previous_post_sort($sort) {
  $sort = "ORDER BY p.post_title DESC LIMIT 1";
  return $sort;
}
function filter_previous_post_where($where) {
  global $post, $wpdb;
  return $wpdb->prepare("WHERE p.post_title < '%s' AND p.post_type = 'post' AND p.post_status = 'publish'",$post->post_title);
}
add_filter('get_next_post_sort',   'filter_next_post_sort');
add_filter('get_next_post_where',  'filter_next_post_where');
add_filter('get_previous_post_sort',  'filter_previous_post_sort');
add_filter('get_previous_post_where', 'filter_previous_post_where');

Source: Snipplr

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

With the help of the snippet below, you will be able to position admin metaboxes before editor.

function positioning_metaboxes() {
	global $post;
	if ( get_post_type($post) == 'post') {
	?>
		<script type="text/javascript">
			jQuery('#normal-sortables').insertBefore('#postdivrich');
		</script>
	<?php
	}
};
add_action( 'admin_footer', 'positioning_metaboxes' );

Snippet Source/Credit: Snipplr

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

You did get visitors via mobile but how you can keep a track of that. Well, using the following snippet below will let you detect that whether your website is access through mobile or not.

include('mobile_device_detect.php');
$mobile = mobile_device_detect();
if ($mobile==true) {
    // Edit this URL to point to the location you'd like to redirect to
    header( 'Location: http://your-website.com/?theme=Your_Mobile_Theme' ) ;
}

Snippet Source/Credit: WebDesignLedger.com

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

The following snippet will let you display categories drop-down menu in WordPress.

<form action="<?php bloginfo('url'); ?>/" method="get"  >
		<?php
			$select = wp_dropdown_categories('show_option_none=Επιλέξτε Κατηγορία:&show_count=0&heirarchial=1&orderby=ID&echo=0');
			$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
			echo $select;
		?>
		<noscript><input type="submit" value="View" /></noscript>
		</form>

Snippet Source/Credit: Snipplr

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

The following snippet will let you remove the code which got added for an iframe injection.

# 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

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

The following snippet will let you remove the dashboard widgets in your WordPress website.

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

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

The following snippet will let you clean dashboard meta boxes in WordPress.

remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_primary', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_secondary', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
        remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' );
        remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' );
        remove_meta_box( 'dashboard_activity', 'dashboard', 'normal' );
}
add_action( 'admin_init', 'remove_dashboard_meta' );

Snippet Source/Credit: WordPress Codex

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Adding the following snippet to your theme’s functions.php file will let you print current WordPress template being used.

<?php
add_action( 'wp_head', 'admin_print_template_used' );
  function admin_print_template_used() {
  global $template, $current_user, $wp_admin_bar;
  get_currentuserinfo();
  if ( !is_user_logged_in() && $current_user->ID != '1' )
	return;
if ( is_admin_bar_showing() )
	$wp_admin_bar->add_menu( array(
		'parent' => false,
		'id' => 'template',
		'title' => $template,
		'href' => '#'
	));
else
	print_r( $template );
}
// START THE SCRIPT TO PUSH ADMIN BAR TO BOTTOM
	function fb_move_admin_bar() {
    echo '
<style type="text/css">
  body {
  padding-bottom: 28px;
  }
  body.admin-bar #wphead {
     padding-top: 0;
  }
  body.admin-bar #footer {
     padding-bottom: 28px;
  }
  #wpadminbar {
      top: auto !important;
      bottom: 0;
  }
  #wpadminbar .quicklinks .menupop ul {
      bottom: 28px;
  }
</style>';
}
// on backend area
add_action( 'admin_head', 'fb_move_admin_bar' );
// on frontend area
add_action( 'wp_head', 'fb_move_admin_bar' );
?>
Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Without any second thought, WP-PageNavi is one such plugin which everyone knows well, which everyone love very much and which everyone wants to get installed in their WordPress website. But, certainly, just like our other snippets tips, for this also, we are having something for you. It’s pretty simple, on copying and pasting the following snippet in your WordPress website, you will be able to have the WordPress pagination active and that too without the use of any plugin.

global $wp_query;
$total = $wp_query->max_num_pages;
// only bother with the rest if we have more than 1 page!
if ( $total > 1 )  {
     // get the current page
     if ( !$current_page = get_query_var('paged') )
          $current_page = 1;
     // structure of "format" depends on whether we're using pretty permalinks
     $format = empty( get_option('permalink_structure') ) ? '&page=%#%' : 'page/%#%/';
     echo paginate_links(array(
          'base' => get_pagenum_link(1) . '%_%',
          'format' => $format,
          'current' => $current_page,
          'total' => $total,
          'mid_size' => 4,
          'type' => 'list'
     ));
}

Snippet Source/Credit: Smashing Magazine

Read Full Article
Visit website
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

The following snippet will let you add your own social icons as scrolling buttons in WordPress.

<div>
<a  title="RSS" href="YOUR RSS FEED URL HERE"><img src="YOUR RSS IMAGE URL HERE"/></a>
<a  title="Twitter" href="YOUR TWITTER PAGE URL HERE"><img src="YOUR TWITTER IMAGE URL HERE /></a>
<a  title="Contact" href="YOUR EMAIL ADDRESS"><img src="YOUR CONTACT IMAGE URL HERE" /></a>
<a  title="Facebook" href="YOUR FACEBOOK PAGE URL HERE"><img src="YOUR FACEBOOK IMAGE URL HERE" /></a>
</div>

Snippet Source/Credit: Snipplr

Read Full Article
Visit website

Read for later

Articles marked as Favorite are saved for later viewing.
close
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Separate tags by commas
To access this feature, please upgrade your account.
Start your free month
Free Preview