Skip to content

Instantly share code, notes, and snippets.

@Steven-Rose
Steven-Rose / gist:4199020
Created December 3, 2012 23:21
Drupal: Title/Page URLs
SELECT node.nid, node.type, node_revision.title, url_alias.alias AS url, if(node.changed = 0,FROM_UNIXTIME(node.created),FROM_UNIXTIME(node.changed)) AS last_modified
FROM node INNER JOIN node_revision ON (node.vid = node_revision.vid) INNER JOIN url_alias ON (url_alias.source = CONCAT('node/', node_revision.nid))
WHERE node.status = 1
ORDER BY url;
@Steven-Rose
Steven-Rose / gist:4159376
Created November 28, 2012 06:22
Drupal: Flush cache
truncate table `cache`;
truncate table `cache_admin_menu`;
truncate table `cache_block`;
truncate table `cache_bootstrap`;
truncate table `cache_field`;
truncate table `cache_filter`;
truncate table `cache_form`;
truncate table `cache_image`;
truncate table `cache_libraries`;
truncate table `cache_menu`;
@Steven-Rose
Steven-Rose / gist:3943830
Created October 24, 2012 04:27
VI: Select all + delete, select all + copy
Select all and delete (actually move to buffer)
:%d
Select all and copy to buffer
:%y
Use p to paste the buffer.
@Steven-Rose
Steven-Rose / gist:2045328
Created March 15, 2012 17:07
WP: Add Google+ button to your posts automatically (updates todo)
add_filter('the_content', 'wpr_google_plusone');
function wpr_google_plusone($content) {
$content = $content.'<div class="plusone"><g:plusone size="tall" href="'.get_permalink().'"></g:plusone></div>';
return $content;
}
add_action ('wp_enqueue_scripts','wpr_google_plusone_script');
function wpr_google_plusone_script() {
wp_enqueue_script('google-plusone', 'https://apis.google.com/js/plusone.js', array(), null);
}
@Steven-Rose
Steven-Rose / gist:2027368
Created March 13, 2012 07:07
WP: Obfuscate email addresses
[mailto][email protected][/mailto]
function mail_shortcode( $atts , $content=null ) {
for ($i = 0; $i < strlen($content); $i++) $encodedmail .= "&#" . ord($content[$i]) . ';';
return '<a href="mailto:'.$encodedmail.'">'.$encodedmail.'</a>';
}
add_shortcode('mailto', 'mail_shortcode');
@Steven-Rose
Steven-Rose / gist:2027360
Created March 13, 2012 07:05
WP: Simpler login url
http://website.com/login
RewriteRule ^login$ http://yoursite.com/wp-login.php [NC,L]
@Steven-Rose
Steven-Rose / gist:1979604
Created March 5, 2012 17:23
WP: Replace excerpt ellipsis with post permalink
function replace_excerpt($content) {
return str_replace('[...]',
'... <div class="more-link"><a href="'. get_permalink() .'">Continue Reading</a></div>',
$content
);
}
add_filter('the_excerpt', 'replace_excerpt');
- Via http://css-tricks.com/snippets/wordpress/replace-excerpt-ellipsis-with-permalink/
@Steven-Rose
Steven-Rose / gist:1895294
Created February 23, 2012 22:02
WP: Add extra contact methods from user info
function add_contact_methods( $contactmethods ) {
// Add Google Profiles
$contactmethods['google_profile'] = 'Google Profile URL';
return $contactmethods;
}
add_filter( 'user_contactmethods', 'add_contact_methods', 10, 1);
Author.php
@Steven-Rose
Steven-Rose / gist:1895273
Created February 23, 2012 21:54
WP: Allow authors to add rel="me"
function yoast_allow_rel() {
global $allowedtags;
$allowedtags['a']['rel'] = array ();
}
add_action( 'wp_loaded', 'yoast_allow_rel' );
Via: http://yoast.com/wordpress-rel-author-rel-me/
@Steven-Rose
Steven-Rose / gist:1772336
Created February 8, 2012 19:12
WP: Uploads directory path
$upload_dir = wp_upload_dir();
echo $upload_dir['baseurl'];