3125 readersIncludes are a very handy functionnality of the PHP language. Unfortunely, there's no built in solution to include posts in other posts in WordPress. Today's recipe is a shortcode that will allow you to finally do includes. Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for
3266 readersOne thing that WordPress doesn’t have the ability to do “out-of-the-box” is do includes, in the sense of including the content of one post into the content of another post directly in the post editor. For the umpteenth time around here, shortcodes to the rescue! This issue came up while my co-worker Tim at Wufoo
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
2695 readersWe covered how to run a shortcode in a widget. But what about inserting a widget with a shortcode? I recently had this situation come up. I had a single page where I just wanted to be able to chuck in a widget without the whole rigmarole of creating a special widgetized area and probably
4510 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
-
2313 readersJust a very quick tip but nonetheless an important one. Many of you will be using any number of plugins or the database query that's been doing the rounds recently to display your most popular posts. That code/plugin is no longer needed as WordPress' query_posts can now display your most commented posts.You really should be
4806 readersWordPress provides several navigational template tags to make it easy for visitors to surf your pages. There are basically two different types of template tags used for chronological post navigation:
posts_nav_link() – for navigating various archive (non-single) pages
previous_post_link() & next_post_link() – for navigating single-post pages
These template tags output the HTML markup required to create the actual
8753 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
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
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