Wordpress Trick: Hide Admin Panels From Specific User Roles
When you’re building a Wordpress website for a client, sometimes you’ll want to hide certain admin panels from specific user roles; do editors really need “custom fields”? Drop the following code into your functions.php file to hide the Custom Fields meta-box from editors.
function hide_meta_boxes() {
remove_meta_box(’postcustom’,'post’,'normal’);
remove_meta_box(’postcustom’,'page’,'normal’);
}
if [...]
Wordpress Trick: Google MP3 Player Shortcode
Here’s another Wordpress shortcode which is quite useful. It piggybacks on Googles excellent Flash-based MP3 player (the one they use in Gmail and so on), makes it easy to embed playable MP3s in your posts. Syntax: . Dump this in your functions.php:
function mp3player($attr) {
$src = str_replace("=", "", $attr[0]);
return ‘<embed type="application/x-shockwave-flash" src="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl=’.$src.’" width="100%" height="27" allowscriptaccess="never" quality="best" [...]
Wordpress Trick: Create A Google Viewer PDF Shortcode [Update]
Want your PDFs to view through Google Reader? Wrap it in a shortcode like this: . Drop the following in your functions.php:
function pdflink($attr, $content) {
return ‘<a class="pdf" href="http://docs.google.com/viewer?url=’ . $attr[’href’] . ‘">’.$content.’</a>’;
}
add_shortcode(’pdf’, ‘pdflink’);
[Update]: Here’s an updated shortcode function which allows you to also embed PDFs using this syntax: . Note how it’s just a tad [...]
Wordpress Trick: Output Content In Two Columns Separated By <!–more–> Tag [Updated]
Need to split up your Wordpress content in two columns without too much of a hassle? How about if you could do that by simply inserting the <!–more–> to indicate where you want the split? Well that’s what you can do using this trick.
Replace the_content(); in your theme with this code. That probably means editing [...]
Sliding Doors In Wordpress
A default Wordpress page menu is built like this:
<?php
wp_page_menu(array(’depth’=>’0′, ’sort_column’=>’menu_order’));
?>
– which outputs a plain menu, <li><a href=” … “>Menu Item</a></li> and so on.
If you want to use the sliding doors CSS technique, however, you need more markup. So do this:
<?php
echo preg_replace(’@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i’, ‘<li$1><a$2><span>$3</span></a>’, wp_page_menu(array(’echo’=>false,’depth’=>’0′, ’sort_column’=>’menu_order’)) );
?>
– which’ll output this a more CSS friendly markup: [...]
Wordpress 3
Work has started on version 3 of Wordpress, and while I’m looking forward to custom post types (so I can build “Add News”, “Add Employee”, “Add Video” sections), the big news is the merge with Wordpress Multi User. Rumors are, it’ll be renamed Wordpress Multi Site.
Image Symlinks
Image Symlinks is born of a desire to speed up and simplify Wordpress post images, while retaining quality. Very briefly, it works like this:
Upload large source image
Use Symlink-image-button to insert image into post
Decide width and/or height of inserted image
How’s that different from using the built-in Wordpress image upload and insertion mechanism? To put it shortly, [...]
Wordpress QuickTip: Pagination
For some websites, Wordpress’ builtin pagination feature (<!–nextpage–>) is supremely useful. Storing here, as much for my own posterity as for yours, a few tricks to get it up and running.
Restore the “Nextpage” button in the Visual editor by adding the following to your functions.php:
/**
* Restore Nextpage Visual Editor button
*/
add_filter(’mce_buttons’,'nextpage’);
function nextpage($btns) {
$pos [...]
Wordpress: Create Your Own YouTube Embed Code
I have yet to find a good way of embedding YouTube videos in Wordpress posts. If you copy the embed code YouTube provides, it’ll work unless you switch to the visual editor which mangles such code. If you look for a plugin to help you with the embedding, you’re in for an experience less pleasant [...]
Tweaking My Ratings Plugin: Pennies For Your Thoughts [Update]
If you’re a b-movie critic and blogger, you should be using my Ratings Short-tags plugin for Wordpress. It allows you to easily insert star or heart ratings that look like this: ♥♥♥♥♥♥.
At the time of the plugins release, a requested feature was the ability to display a list of posts that contained similar ratings (for [...]