4003 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
3910 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
1243 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
3809 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
3344 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
6184 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
8731 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
8426 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" =>
7000 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
6678 readers
PHP
function wps_screenshot($atts, $content = null) {
extract(shortcode_atts(array(
"screenshot" => 'http://s.wordpress.com/mshots/v1/',
"url" => 'http://',
"alt" => 'screenshot',
"width" => '400',
"height" => '300'
), $atts));
return $screen = '';
}
add_shortcode("screenshot", "wps_screenshot");
SHORTCODE
[screenshot url="http://wpsnipp.com" alt="wordpress code snippets for your blog" width="200" height="200"]
Visit wpsnipp.com for details on how to setup this