Skip to content

Instantly share code, notes, and snippets.

@corsonr
corsonr / Redirect a user after login
Created August 7, 2012 08:24
how to redirect a user after login
// Redirect admins to the dashboard and other users elsewhere
add_filter( 'login_redirect', 'xxx_login_redirect', 10, 3 );
function xxx_login_redirect( $redirect_to, $request, $user ) {
// Is there a user?
if ( is_array( $user->roles ) ) {
// Is it an administrator?
if ( in_array( 'administrator', $user->roles ) )
return home_url( '/wp-admin/' );
else
@corsonr
corsonr / Create a custom pagination
Created August 8, 2012 07:24
A simple pagination in a few lines of code
<?php
/* ------------------------------------------------------------------*/
/* PAGINATION */
/* ------------------------------------------------------------------*/
//paste this where the pagination must appear
global $wp_query;
$total = $wp_query->max_num_pages;
// only bother with the rest if we have more than 1 page!
@corsonr
corsonr / Add rel attribute to wordpress gallery
Created August 8, 2012 08:06
simple trick to add rel attribute to wordpress gallery
@corsonr
corsonr / wordpress sitemap
Created August 14, 2012 09:21
create a simple sitemap
<h3>Pages</h3>
<ul><?php wp_list_pages("title_li=" ); ?></ul>
<h3>Feeds</h3>
<ul>
<li><a title="Full content" href="feed:<?php bloginfo('rss2_url'); ?>">Main RSS</a></li>
<li><a title="Comment Feed" href="feed:<?php bloginfo('comments_rss2_url'); ?>">Comment Feed</a></li>
</ul>
<h3>Categories</h3>
<ul><?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0&feed=RSS'); ?></ul>
<h3>All Blog Posts:</h3>
@corsonr
corsonr / Secure email shortcode
Created September 18, 2012 15:16
secure email shortcode
<?php
/* ------------------------------------------------------------------*/
/* SECURE EMAIL SHORTCODE */
/* ------------------------------------------------------------------*/
function xxx_secure_mail( $atts ) {
extract(
shortcode_atts( array(
"mailto" => '',
"txt" => ''
@corsonr
corsonr / Easy Default Parameters
Created September 28, 2012 07:02
Set your default parameters on fresh installs
<?php
/*
Plugin Name: Easy Default Parameters
Plugin URI: http://remicorson.com
Description: Set your own default parameters on a fresh WordPress install
Version: 0.1
Author: Rémi Corson
Author URI: http://remicorson.com
Contributors: Rémi Corson, corsonr
*/
@corsonr
corsonr / BBpress pagination CCS code
Created October 2, 2012 13:58
BBpress pagination CCS code
/* --- BBPRESS PAGINATION --- */
.bbp-pagination-links { list-style:none; font-size:12px; }
.bbp-pagination-links { display:inline; }
.bbp-pagination-links a, .bbp-pagination-links a.next, .bbp-pagination-links a.prev{ display:block; float:left; padding:4px 9px; margin-right:7px; border:1px solid #efefef; }
.bbp-pagination-links span.current { display:block; float:left; padding:4px 9px; margin-right:7px; border:1px solid #efefef; background-color:#f5f5f5; }
.bbp-pagination-links span.dots { display:block; float:left; padding:4px 4px; margin-right:7px; }
@corsonr
corsonr / RCP auto redirection
Created October 9, 2012 07:55
Restrict Content Pro - automatic redirection
// redirection if user is logged in
function rcp_redirect_if_user_is_logged() {
if (is_plugin_active('restrict-content-pro/restrict-content-pro.php')) {
if( is_user_logged_in() ) {
wp_redirect( home_url() ); // replace home_url() by whatever url/page you want
exit;
}
}
}
add_action( 'rcp_after_login_form', 'rcp_redirect_if_user_is_logged' );
@corsonr
corsonr / Add CPTs to search
Created October 13, 2012 09:54
Add CPTs to search
@corsonr
corsonr / gist:4071519
Created November 14, 2012 10:55
Adding BBpress private shortcode
/* ------------------------------------------------------------------*/
/* ADD BBPRESS PRIVATE SHORTCODE */
/* ------------------------------------------------------------------*/
function remi_bbp_shortcodes( $content, $reply_id ) {
return do_shortcode( $content );
}
add_filter('bbp_get_reply_content', 'remi_bbp_shortcodes', 10, 2);
add_filter('bbp_get_topic_content', 'remi_bbp_shortcodes', 10, 2);
function remi_add_bbpress_private_shortcode( $atts, $content = null ) {