Strip Titles from WordPress images
add_filter( 'wp_get_attachment_image_attributes', 'my_no_image_title' );
function my_no_image_title ( $attr ) {
unset( $attr['title'] );
return $attr;
}
Source:
WordPress Stack ExchangeEqual-height columns in jQuery
/*if your columns have unique IDs*/
var highestCol = Math.max ( $('#element1').height(), $('#element2').height() );
$('.elements').height(highestCol);
/*alternative if your columns don't have unique IDs, which was the case when I implemented the above*/
var n = 1;
$('.textwidget').each(function(){
var id = 'element' + n;
$(this).attr('id',id);
n++;
});
/*extend this if you have more than two columns, we're just using two for the example*/
var highestCol = Math.max($('#element1').height(),$('#element2').height());
$('.textwidget').height(highestCol);
/*if you don't know how many columns there are (not sure why that would be), you can use a for loop and the final value of n to cycle through*/
Source:
Broken LinksUpgrade a user from subscriber to editor
$u = new WP_User( $userID ); // Remove role $u->remove_role( 'subscriber' ); // Add role $u->add_role( 'editor' );
Source:
Stack ExchangeWordPress: Exclude the_post_thumbnail from gallery shortcode
function exclude_thumbnail_from_gallery($null, $attr)
{
if (!$thumbnail_ID = get_post_thumbnail_id())
return $null; // no point carrying on if no thumbnail ID
// temporarily remove the filter, otherwise endless loop!
remove_filter('post_gallery', 'exclude_thumbnail_from_gallery');
// pop in our excluded thumbnail
if (!isset($attr['exclude']) || empty($attr['exclude']))
$attr['exclude'] = array($thumbnail_ID);
elseif (is_array($attr['exclude']))
$attr['exclude'][] = $thumbnail_ID;
// now manually invoke the shortcode handler
$gallery = gallery_shortcode($attr);
// add the filter back
add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2);
// return output to the calling instance of gallery_shortcode()
return $gallery;
}
add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2);
Source:
Stack OverflowHide HTML until Javascript & CSS are completely loaded
/*set body visibility to hidden in your css*/
body {
visibility: hidden;
}
/*add this to your javascript*/
jQuery(document).ready(function(){
/* Show the HTML page only after the js and css are completely loaded */
delayShow();
});
function delayShow() {
var secs = 1000;
setTimeout('jQuery("body").css("visibility","visible");', secs);
}
Source:
Eureka!Remove Personal Options from User Profile
<?php
//add this to functions.php of your theme
function remove_opt_start($adddiv) {
$gettitle = array('#<h3>Personal Options</h3>#');
$adddiv = preg_replace($gettitle, '<div class="hidden">', $adddiv,1);
return $adddiv;
}
function start_remove_opt_start() { ob_start("remove_opt_start"); }
function end_remove_opt_start() { ob_end_flush(); }
function remove_opt_end($addend) {
$getname = array('#<h3>Name</h3>#');
$addend = preg_replace($getname, '</div><h3>Name</h3>',$addend,1);
return $addend;
}
function start_remove_opt_end() { ob_start("remove_opt_end"); }
function end_remove_opt_end() { ob_end_flush(); }
add_action('admin_head','start_remove_opt_start');
add_action('admin_head','start_remove_opt_end');
add_action('admin_footer','end_remove_opt_start');
add_action('admin_footer','end_remove_opt_end');
?>
Source:
WordPress.OrgTest if Category exists in WordPress
<?php
/**
* only in admin area
*
* @param string $cat_name
*/
if ( is_admin() && category_exists('uncategorized') ) // cat_slug, cat_name
return true;
/**
* outside admin area
*
* is_term($term, $taxonomy = '')
* @param int|string $term The term to check
* @param string $taxonomy The taxonomy name to use
*/
if ( is_term( 'uncategorized' , 'category' ) ) // cat_slug, cat_name
return true;
else
return false;
/**
* outside admin area
*
* get_category( $category, $output = OBJECT, $filter = 'raw' )
* @param int|object $category Category ID or Category row object
* @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N
* @param string $filter Optional. Default is raw or no WordPress defined filter will applied.
*/
$cat = get_category(1); // cat_ID
if ( !empty( $cat ) )
return true;
?>
Source:
WP EngineerWordPress redirect functions
/*redirect any user*/
<?php wp_redirect('http://example.com/'); exit; ?>
/*checks whether or not the current user is logged in, and redirects them to the Login Page if not. By default, the user will be redirected back to the page from whence they came (e.g., the downloads page)*/
<?php auth_redirect(); ?>
/*logout*/
/*Logout & redirect to the home page*/
<a href="<?php echo wp_logout_url(home_url()); ?>">Logout</a>
/*Logout & redirect to current page*/
<a href="<?php echo wp_logout_url(get_permalink()); ?>">Logout</a>
/*Logout & redirect to specific URL*/
<a href="<?php echo wp_logout_url('http://example.com/'); ?>">Logout</a>
Source:
digwp.comRedirect users to any page on login
/* redirect to current page */
<a href="<?php echo wp_login_url(get_permalink()); ?>" title="Login">Login to view</a>
/* redirect to home page */
<a href="<?php echo wp_login_url(get_bloginfo('wpurl')); ?>" title="Login">Login to view</a>
/* redirect to some other URL */
<a href="<?php echo wp_login_url('http://www.google.com'); ?>" title="Login">Login to view</a>
Source:
wp recipesDisable PHP timeout
<?php // Disable PHP Timeout example // http://php.snippetdb.com //set php script timeout, 0 to disable set_time_limit(0); // your time consuming code //don't forget to reset to 30 seconds. set_time_limit(30); ?>
