4090 readersHave a bunch of different areas you wish to declare as a widgetized area? Save repetative code by creating a quick array of their names, then loop through that array calling the register_sidebar() function on each one. Elementary PHP stuff here, but hey, it just saved me quite a few lines of code in a
4132 readersI had the occasion yesterday to have a page with a section on it where it would output a very specific set of other pages, which would need to change dynamically. What I could have done is built a special page template for this page, and inside that template run a query_posts() to get these
1338 readers
PHP
add_shortcode("my_text", "my_text");
function my_text() {
return 'nested shortcode';
}
function my_link($atts, $content = null) {
extract(shortcode_atts(array(
"href" => 'http://'
), $atts));
return ''.do_shortcode($content).'';
}
add_shortcode("link", "my_link");
SHORTCODE
[link][my_text][/link]
Visit wpsnipp.com for details on how to setup this WordPress snippet. Share this post. Facebook | StumbleUpon | Delicious | Tweet It | Digg This | DesignBump-It | DesignPoke-it
4666 readersThe post_class() function in WordPress is pretty darn useful. It is used like this, in most templates, in a wrapping div of all the content you are outputting:
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<!-- Post stuff -->
</div>
I was in a circumstance where I wanted to add an additional class to what that
3502 readersIn a WordPress Framework or Basic-Theme are one or several Widget Areas (Sidebars) defined. But how can you remove the widget areas if you don't need them and just confuse other backend users. The line unregister_sidebar('my-sidebar'); in functions.php of Child-Themes doesn't do anything. Why? WordPress loads first the function.php of Child-Themes and then of the
6251 readers
PHP
function html5_video($atts, $content = null) {
extract(shortcode_atts(array(
"src" => '',
"width" => '',
"height" => ''
), $atts));
return '';
}
add_shortcode('video5', 'html5_video');
SHORTCODE
[video5 src="http://your-site/videos/your-video.mp4" width="720" height="480"]
Visit wpsnipp.com for details on how to setup this WordPress snippet. Share this post. Facebook | StumbleUpon | Delicious | Tweet It | Digg This | DesignBump-It | DesignPoke-it
11330 readers
PHP
function html5_audio($atts, $content = null) {
extract(shortcode_atts(array(
"src" => '',
"autoplay" => '',
"preload"=> 'true',
"loop" => '',
"controls"=> ''
), $atts));
return '';
}
add_shortcode('audio5', 'html5_audio');
SHORTCODE
[audio5 src="http://your-site/videos/your-video.mp4" loop="true" autoplay="autoplay" preload="auto" loop="loop" controls=""]
Visit wpsnipp.com for details on how to setup this WordPress snippet. Share this post. Facebook | StumbleUpon | Delicious | Tweet It | Digg This | DesignBump-It | DesignPoke-it
8817 readersDisplay a snapshot of any website
Want to be able to take a snapshot of any website, and display it on your blog? This cool shortcode allows you to do so. Just paste the following code into your functions.php file:
function wpr_snap($atts, $content = null) {
extract(shortcode_atts(array(
"snap" => 'http://s.wordpress.com/mshots/v1/',
"url" =>
4643 readersSave time by replacing your most commonly typed words and phrases with WordPress shortcodes. For example, if you are frequently typing your blog’s URL, you could place the following code your theme’s functions.php file: function shortURL() { return 'http://your-site.com/'; } add_shortcode('myurl', 'shortURL'); Now whenever you write a post in “HTML-mode”, you can include your blog’s
7111 readers
PHP
add_shortcode( 'youtube', 'my_youtube_shortcode' );
function my_youtube_shortcode( $atts ) {
global $wp_embed;
if ( empty($atts['id']) )
return '';
// Construct the YouTube URL
$url = 'http://www.youtube.com/watch?v=' . $atts['id'];
return $wp_embed->shortcode( $atts, $url );
}
PHP
[youtube id="000000"]
Visit