Make text bigger  Make text smaller  Toggle background color  Bookmark/Share


WORKING WITH WORDPRESS SHORTCODES

PBDESIGN-shortcodes Working With WordPress Shortcodes

WordPress shortcodes have been used often in plugins as well as themes as a approach to grasp a single some-more functionality, yet a need to cgange template files. You only type a shortcode word right in to your post. Some plugins as well as themes have have have have have have have make use of of of of of of of of them to supplement eventuality calendars, a tiny for origination announcements, whilst others have have have have have have have make use of of of of of of of of them for inserting contact forms.

Simply, WP shortcodes have been awesome.

However, what if you’re a theme / plugin developer wishing to have have have have have have have make use of of of of of of of of them for your subsequent good product, yet we have no thought where to start? We’re starting to repair which in this tutorial.

1 – Overview – Exactly Where We have been Going

We will begin out by seeking at a elementary ways which we can have have have have have have have make use of of of of of of of of WP shortcodes, afterwards we will pierce onto a tiny some-more modernized tricks. After a have have have make use of of of of sections, I’m starting to uncover we a tiny examples of real-world shortcodes, followed by even some-more ideas / references of what we could do with them.

2 – Getting Into a Basics

The initial we thing we should regularly do when operative with something WordPress, is check a WordPress Codex. It’s a good anxiety as well as starting point.

Shortcodes, identical to only about all else in WordPress, can be combined in a functions.php file, or from inside of your plugin record if you’re building a plugin.

Let’s begin elementary by origination a shortcode which we can have have have have have have have make use of of of of of of of of to supplement a single some-more styles to a tiny text.

1
2
3
4
function extra_style_shortcode( $atts, $content = null ) {
   return '<span style="color: blue; text-decoration: underline;">' . $content . '</span>';
}
add_shortcode('extra-style', 'extra_style_shortcode');

This is a unequivocally elementary e.g. which serves roughly no purpose, yet simply illustrates a basis of shortcode creation. It allows us to do something identical to this in a WP posts/pages:

[extra-style]Hello World![/extra-style]

and have it outputted identical to this:

Hello World!

So what’s happening? It’s simple, we’re simply revelation WordPress to put all of a calm inside of a [ ] . . . [/ ] in to a non-static called $content, afterwards outputting $content inside of a camber tab which has a tiny elementary inline styling practical to it.

Okay, which was easy, right away let’s get in to something a tiny some-more complex. This time we’ll give a capability to conclude a tone of a calm regulating attributes.

1
2
3
4
5
6
7
function extra_style_shortcode( $atts, $content = null ) {
    extract(shortcode_atts(array(
		"color" => 'blue',
	), $atts));
   return '<span style="color: ' . $color . '; text-decoration: underline;">' . $content . '</span>';
}
add_shortcode('extra-style', 'extra_style_shortcode');

Now we can do this:

[extra-style color=red]Hello World![/extra-style]

and we’ll see: Hello World!

or:

[extra-style color=orange]Hello World![/extra-style]

and we’ll see: Hello World!.

This e.g. uses this bit of code

    extract(shortcode_atts(array(
		"color" => 'blue',
	), $atts));

to remove a report inputted by a user for a non-static color. We have additionally tangible a default tone of blue in box no tone is defined.

Again, this e.g. is flattering many useless, yet a morality creates it unequivocally easy to understand.

Let’s get only a tiny bit some-more formidable prior to relocating on.

1
2
3
4
5
6
7
8
9
function extra_style_shortcode( $atts, $content = null ) {
    extract(shortcode_atts(array(
	"color" => 'blue',
        "size" => '14px',
        "padding" => '0px',
	), $atts));
   return '<span style="color: ' . $color . '; padding: ' . $padding . '; font-size: ' . $size . '; text-decoration: underline;">' . $content . '</span>';
}
add_shortcode('extra-style', 'extra_style_shortcode');

By regulating a shortcode identical to this inside of a retard of text:

[extra-style color=purple size=18px padding=5px]Hello World![/extra-style]

we could see something identical to this:

Elementum odio? Sed, Hello World! proin pulvinar eros nascetur, massa urna aliquam turpis elit, adipiscing mauris montes ac, vel lacus placerat in adipiscing ridiculus rhoncus.

Well that’s sufficient of a purposeless examples; let’s demeanour at a tiny genuine shortcode examples.

3 – Making an Information Box

This shortcode e.g. will let we embody a good tiny summary box at a tip of your post to assistance locate readers’ eyes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function box_shortcode( $atts, $content = null )
{
    extract( shortcode_atts( array(
      'color' => 'yellow',
      'size' => 'medium',
      ), $atts ) );
 
      return '
		<style type="text/css">
		.shortcode_box {
			padding: 2px 4px;
			border: 1px plain #ccc;
		}
		.yellow {
			background: #ffd149;
			color: #666;
		}
		.blue {
			background: #a0c5ef;
			color: #333;
		}
		.gray {
			background: #f0f0f0;
			color: #333;
		}
		</style>
 
      <div class="shortcode_box ' . $size . ' ' .  $color . '">' . $content . '</div>';
 
}
add_shortcode('box', 'box_shortcode');

Now we can have have have have have have have make use of of of of of of of of a “box” shortcode to furnish something identical to this

This is a summary box with critical report we should read.

by regulating this shortcode:

[box color=yellow]This is a summary box with critical report we should read.[/box]

By becoming opposite a color variable, we can have opposite colors of boxes:

This is a summary box with critical report we should read.
This is a summary box with critical report we should read.

With a tiny some-more CSS, we could additionally carry out a distance of a box, yet I’ll leave which to you.

4 – Create a Download Button

The routine for formulating a download symbol is unequivocally identical to formulating a summary box: we simplu hang a calm of a symbol inside of a div with a tiny special CSS3 styles practical to it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function button_shortcode( $atts, $content = null )
{
    extract( shortcode_atts( array(
      'color' => 'blue',
      'size' => 'medium',
      ), $atts ) );
 
      return '
		<style type="text/css">
		.shortcode_button {
			padding: 2px 8px;
			border: 1px plain #ccc;
			border-radius: 10px;
			-webkit-border-radius: 10px;
			-moz-border-radius: 10px;
		}
		.black {
			background: #ffd149;
			background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#636363), to(#332F2F));
			background: -moz-linear-gradient(19% 75% 90deg,#332F2F, #636363);
			color: #f0f0f0;
			border-top-color: #1c1c1c;
			border-left-color: #1c1c1c;
			border-right-color: #525252;
			border-bottom-color: #525252;
		}
		.blue {
			background: #a0c5ef;
			background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#508BC7), to(#203F75));
			background: -moz-linear-gradient(19% 75% 90deg,#203F75, #508BC7);
			color: #f0f0f0;
			border-top-color: #023778;
			border-left-color: #023778;
			border-right-color: #26609e;
			border-bottom-color: #26609e;
		}
 
		.large	{
			width: 200px;
		}
		.medium	{
			width: 120px;
		}
		.small	{
			width: 80px;
		}
		</style>
 
      <div class="shortcode_button ' . $size . ' ' .  $color . '">' . $content . '</div>';
 
}
add_shortcode('button', 'button_shortcode');

We can arrangement a symbol by using:

[button color=black size=medium]<a href="#">Download</a>[/button]

which will give us:
black_button Working With WordPress Shortcodes

In sequence to carry out a distance or tone of a button, all we have to do is emanate a CSS difficulty with a same name as a worth we submit for a size / color variables. For example, if we do size=large in a shortcode, we need a CSS difficulty called large in a stylesheet. You can see we have enclosed a single some-more styles in my on top of e.g. to spell out a tiny probable options.

5 – Buttons as well as Boxes Together

Shortcodes have been good since they additionally let us mix them to a outcome like:

Porta ultricies. Amet odio amet, pellentesque elementum adipiscing sagittis enim, eu, proin placerat sed pid cum? Dictumst turpis integer. Adipiscing, porttitor scelerisque! Lorem turpis porttitor.

Integer in, odio mattis ac! Nascetur augue odio in risus, arcu nunc, phasellus ultrices lectus velit, et tincidunt tristique. Integer vel pulvinar purus magnis.

by regulating a shortcode like:

[box color=blue]Porta ultricies. Amet odio amet, pellentesque elementum adipiscing sagittis enim, eu, proin placerat sed pid cum? Dictumst turpis integer. Adipiscing, porttitor scelerisque! Lorem turpis porttitor.
 
Integer in, odio mattis ac! Nascetur augue odio in risus, arcu nunc, phasellus ultrices lectus velit, et tincidunt tristique. Integer vel pulvinar purus magnis.
 
[button color=black size=small]<a href="#">Download[/button][/box]

There is a single tiny hitch, though. By default, WordPress does not concede we to hide shortcodes inside of alternative shortcodes. In sequence to get around that, we have to supplement a line to a functions.php or categorical plugin file:

add_filter('the_content', 'do_shortcode');

This will have WordPress routine both sets of shortcodes.

6 – Show Related Posts

This is a unequivocally accessible shortcode we can have have have have have have have make use of of of of of of of of to arrangement a list of posts associated to a stream post by comparing tags.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function related_posts_shortcode( $atts ) {
	extract(shortcode_atts(array(
	    'limit' => '5',
	), $atts));
 
	global $wpdb, $post, $table_prefix;
 
	if ($post->ID) {
		$retval = '<ul>';
 		// Get tags
		$tags = wp_get_post_tags($post->ID);
		$tagsarray = array();
		foreach ($tags as $tag) {
			$tagsarray[] = $tag->term_id;
		}
		$tagslist = implode(',', $tagsarray);
 
		// Do a query
		$q = "SELECT p.*, count(tr.object_id) as count
			FROM $wpdb->term_taxonomy AS tt, $wpdb->term_relationships AS tr, $wpdb->posts AS p WHERE tt.taxonomy ='post_tag' AND tt.term_taxonomy_id = tr.term_taxonomy_id AND tr.object_id  = p.ID AND tt.term_id IN ($tagslist) AND p.ID != $post->ID
				AND p.post_status = 'publish'
				AND p.post_date_gmt < NOW()
 			GROUP BY tr.object_id
			ORDER BY equate DESC, p.post_date_gmt DESC
			LIMIT $limit;";
 
		$related = $wpdb->get_results($q);
 		if ( $related ) {
			foreach($related as $r) {
				$retval .= '
	<li><a title="'.wptexturize($r->post_title).'" href="'.get_permalink($r->ID).'">'.wptexturize($r->post_title).'</a></li>
';
			}
		} else {
			$retval .= '
	<li>No associated posts found</li>
';
		}
		$retval .= '</ul>
';
		return $retval;
	}
	return;
}
add_shortcode('related_posts', 'related_posts_shortcode');

We can uncover a associated posts by using:

[related_posts]

Credit goes to Blue Anvil for this shortcode.

7 – Drop Caps With a Shortcode

Drop caps have been flattering as well as have your articles demeanour unequivocally nice. They can unequivocally supplement a tiny good item to post as well as have your site mount out on top of a rest.

1
2
3
4
5
6
function dropcap($atts, $content = null) {
	return '
<div class="dropcap">'.$content.'</div>
;';
}
add_shortcode('dropcap', 'dropcap');

The CSS:

1
2
3
4
5
6
7
.dropcap {
display:block;
float:left;
font-size:50px;
line-height:40px;
margin:0 5px 0 0;
}

Use it with:

[dropcap]M[/dropcap]auris ut lectus erat. In ...

Credit for this shortcode goes to TutToaster.

8 – Custom Post Type Query

Let’s contend which we have set up a law post sort called News as well as we instruct to arrangement all posts inside which law post sort on a page called Articles. You could do it with a formula below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function news_shortcode()
{
	//The Query
	query_posts('post_type=news');
	//The Loop
	if ( have_posts() ) : while ( have_posts() ) : the_post();
		echo	'<h3><a href="'; echo the_permalink(); echo '">'; echo the_title(); echo '</a></h3>';
		echo the_excerpt();
	endwhile; else:
	endif;
 
	//Reset Query
	wp_reset_query();
}
add_shortcode('news', 'news_shortcode');

Then arrangement a headlines posts on your Articles page by regulating this shortcode:

[news]

9 – Display Posts from Category on Page

Very identical to a shortcode e.g. above, we can additionally arrangement singular series of posts from inside of a sold difficulty regulating a shortcode identical to this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function category_shortcode( $atts )
{
extract(shortcode_atts(array(
	    'limit' => '5',
            'category' => '',
	), $atts));
	//The Query
	query_posts('category=' . $id . 'posts_per_page=' . $limit);
	//The Loop
	if ( have_posts() ) : while ( have_posts() ) : the_post();
		echo	'<h3><a href="'; echo the_permalink(); echo '">'; echo the_title(); echo '</a></h3>';
		echo the_excerpt();
	endwhile; else:
	endif;
 
	//Reset Query
	wp_reset_query();
}
add_shortcode('category', 'category_shortcode');

You can list a posts using:

[category id=# limit=5]

Just reinstate # with a ID of a difficulty we instruct to display.

10 – Great Examples of Other Possible Shortcodes

I’ve shown we a couple of examples, both of my own as well as other’s creation, right away let me give we even some-more examples of overwhelming things we could do.

Joen Asmussen of NoScope.com combined a unequivocally nifty tiny shortcode to have a Google PDF Viewer.

Check it out here

Jean Baptiste, of WP-Recipes combined a shortcode to arrangement a “ReTweet” or “TweetMeme” buttons in your posts. Find it here.

Justin Tadlock done a good plugin which turns all (or most) WordPress template tags in to shortcodes so which they can be used inside of a post editor. Download a Plugin.

A couple of weeks ago we wrote a shortcode plugin of my own (sorry, couldn’t leave myself out!). It’s a shortcode application plugin which allows we to insert a accumulation of summary boxes as well as web buttons around shortcodes (similar to a tiny of a examples I’ve used above). Check out WP Utility Shortcodes.

11 – Some More Ideas

  • Use shortcodes for displaying hit forms
  • use shortcodes for displaying a Google map
  • Shortcodes to arrangement writer bios
  • A shortcode which outputs all of your amicable network info
  • Shortcodes for picture galleries
  • Shortcodes for jQuery picture sliders

Have we seen any alternative engaging uses of shortcodes? Do we have have have have have have have have make use of of of of of of of of of them in your site already?

 Working With WordPress Shortcodes

See a strange post:
Working With WordPress Shortcodes


Get Auto Caffeinated Content for Your WordPress Blog



MOBILE APPLICATION

Offshore Mobile Application Development Company | Hire Mobile Application Developer | Hire iPad Appl
 Mobile Application  Mobile Application  Mobile Application  Mobile Application

 Mobile Application

More:
Mobile Application


Get Auto Caffeinated Content for Your WordPress Blog



THINK BRILLIANT

Think Brilliant Media Studios
 Think Brilliant  Think Brilliant  Think Brilliant  Think Brilliant

 Think Brilliant

Read some-more here:
Think Brilliant


Get Auto Caffeinated Content for Your WordPress Blog



CARRINGTON BUILD THEME RELEASED INTO THE WILD

carringtonbuild-teaser Carrington Build theme released into the wild

Alex King, owners of Crowd Favorite, WordPress HelpCenter, as well as writer of roughly dual dozen Plugins, has voiced a brand new product: Carrington Build.

Carrington Build is a WordPress thesis not distinct (but on a alternative palm utterly a bit unlike) alternative WordPress frameworks. What Build brings to a list is a capability to blueprint page elements, with a WordPress page/post revise screen, though in contact with code.

Build seems similar to a thesis which is perplexing tough to work a sure approach rsther than than to look a sure way. The page blueprint underline stands out, even between alternative rarely stretchable CMS WordPress themes.

For those which wish to collect up Carrington Build for growth purposes, a developer book is accessible for $499. For those who wish to try it out, though who don’t have a customer work to clear a developer cost tag, Carrington Business is built on Build as well as comes it at an easier-to-swallow $150. For those meddlesome in a functionality, though not a growth work, King’s WordPress HelpCenter offers options for integrating Build in to stream WordPress themes.

Watch a demo videos as well as leave a criticism revelation us what we consider — is this indeed a subsequent step in WordPress themes? Will we make use of it on your own projects?

Click here to perspective a embedded video.

Click here to perspective a embedded video.

Still have questions about Build? King has posted an FAQ over on his blog which covers a series of good questions.

See a strange post:
Carrington Build thesis expelled in to a wild


Get Auto Caffeinated Content for Your WordPress Blog



100 MILLION PLUGIN DOWNLOADS AND COUNTING

WordPress 3.0 Thelonious upheld 3 million downloads yesterday, as well as currently the plugin directory followed fit with a miracle of a own: 100 million downloads.

The WordPress community’s expansion over a years has been tremendous, as well as you wish to reinvest in it. So we’re receiving a subsequent dual months to combine on mending WordPress.org. A vital partial of which will be mending a infrastructure of a plugins directory. More than 10,000 plugins have been in a directory, each a single of them GPL concordant as well as giveaway as in both drink as well as speech. Here’s what you have in mind:

We wish to yield developers a collection they need to set up a most appropriate probable plugins. We’re starting to yield improved formation with a forums so you can await your users. We’ll have some-more census data accessible to you so you can investigate your user base, as well as over time you idea to have it simpler for you to manage, build, as well as recover localized plugins.

We wish to urge how a core program functions with your plugin as well as a plugin directory. We’re starting to concentration on ensuring seamless upgrades by creation a most appropriate probable determinations about compatibility, as well as suggest redundant improvements to a plugin installer. And you additionally wish to give you a improved developer apparatus set similar to SVN notifications as well as improvements to a bug tracker.

We’re additionally starting to examination with alternative good ideas to assistance a village assistance plugin authors. We wish it to be easy for you to suggest comments to plugin authors as well as a community, together with user reviews as well as improved feedback. We might examination with an embracing a cause routine for deserted plugins as a approach to reanimate dark gems in a directory. I’m not certain there is a improved approach to uncover how extendable WordPress is as well as how overwhelming this village is at a same time.

As Matt pronounced in a 3.0 recover announcement, a idea isn’t to have all undiluted all at once. But you consider incremental improvements can yield us with a good bottom for 3.1 as well as beyond, as well as for a tens of millions of users, as well as hundreds of millions of plugin downloads to come.

More: 
100 Million Plugin Downloads as well as Counting


Get Auto Caffeinated Content for Your WordPress Blog



100 MILLION PLUGIN DOWNLOADS AND COUNTING

WordPress 3.0 Thelonious upheld 3 million downloads yesterday, as well as currently the plugin directory followed fit with a miracle of a own: 100 million downloads.

The WordPress community’s expansion over a years has been tremendous, as well as you wish to reinvest in it. So we’re receiving a subsequent dual months to combine on mending WordPress.org. A vital partial of which will be mending a infrastructure of a plugins directory. More than 10,000 plugins have been in a directory, each a single of them GPL concordant as well as giveaway as in both drink as well as speech. Here’s what you have in mind:

We wish to yield developers a collection they need to set up a most appropriate probable plugins. We’re starting to yield improved formation with a forums so you can await your users. We’ll have some-more census data accessible to you so you can investigate your user base, as well as over time you idea to have it simpler for you to manage, build, as well as recover localized plugins.

We wish to urge how a core program functions with your plugin as well as a plugin directory. We’re starting to concentration on ensuring seamless upgrades by creation a most appropriate probable determinations about compatibility, as well as suggest redundant improvements to a plugin installer. And you additionally wish to give you a improved developer apparatus set similar to SVN notifications as well as improvements to a bug tracker.

We’re additionally starting to examination with alternative good ideas to assistance a village assistance plugin authors. We wish it to be easy for you to suggest comments to plugin authors as well as a community, together with user reviews as well as improved feedback. We might examination with an embracing a cause routine for deserted plugins as a approach to reanimate dark gems in a directory. I’m not certain there is a improved approach to uncover how extendable WordPress is as well as how overwhelming this village is at a same time.

As Matt pronounced in a 3.0 recover announcement, a idea isn’t to have all undiluted all at once. But you consider incremental improvements can yield us with a good bottom for 3.1 as well as beyond, as well as for a tens of millions of users, as well as hundreds of millions of plugin downloads to come.

View strange post here: 
100 Million Plugin Downloads as well as Counting


Get Auto Caffeinated Content for Your WordPress Blog



WORDPRESS IMPORT NOT INCLUDE IN WP CORE

WordPress came with multiform code new or altered facilities – a single underline which altered is a functionality to import calm from alternative systems.

WordPress offers underneath “Tools” to import interpretation of alternative applications or a XML-file of an one more WordPress installation. But given WordPress 3.0 we need a Plugin since it is no longer in WordPress core. The designation of a Plugin is easy as well as has a common stairs to turn on a Plugin.

wp-importer-300x112 WordPress Import Not Include In WP Core

This is a initial time, which WordPress is starting in to a citation of regulating Core-Plugins. There have been most formats accessible if we check out a profile of WordPress, as well as may be someone can emanate one more importers for alternative formats.


Related posts:


WP Engineer Favicon Thanks for subscribing a feed! Sponsor a WP Engineer Blog as well as get your code in front of multiform hundred users per day!
© WP Engineer Team, All rights indifferent (Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)

Read a strange post: 
WordPress Import Not Include In WP Core


Get Auto Caffeinated Content for Your WordPress Blog



WORDPRESS IMPORT NOT INCLUDE IN WP CORE

WordPress came with multiform code new or altered facilities – a single underline which altered is a functionality to import calm from alternative systems.

WordPress offers underneath “Tools” to import interpretation of alternative applications or a XML-file of an one more WordPress installation. But given WordPress 3.0 we need a Plugin since it is no longer in WordPress core. The designation of a Plugin is easy as well as has a common stairs to turn on a Plugin.

wp-importer-300x112 WordPress Import Not Include In WP Core

This is a initial time, which WordPress is starting in to a citation of regulating Core-Plugins. There have been most formats accessible if we check out a profile of WordPress, as well as may be someone can emanate one more importers for alternative formats.


Related posts:


WP Engineer Favicon Thanks for subscribing a feed! Sponsor a WP Engineer Blog as well as get your code in front of multiform hundred users per day!
© WP Engineer Team, All rights indifferent (Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)

View strange here:
WordPress Import Not Include In WP Core


Get Auto Caffeinated Content for Your WordPress Blog



10 RESOURCES TO HELP YOU CREATE A KILLER WORDPRESS OPTIONS PAGE

Options panels have been a contingency for WordPress themes these days. So here have been a little overwhelming tutorials, articles, as well as templates to assistance we have a torpedo options page for your subsequent WordPress theme.

www.FeedBurner.com) 10 Resources to Help You Create a Killer WordPress Options Page 10 Resources to Help You Create a Killer WordPress Options Page

Here is a original: 
10 Resources to Help You Create a Killer WordPress Options Page


Get Auto Caffeinated Content for Your WordPress Blog



10 RESOURCES TO HELP YOU CREATE A KILLER WORDPRESS OPTIONS PAGE

Options panels have been a contingency for WordPress themes these days. So here have been a little overwhelming tutorials, articles, as well as templates to assistance we have a torpedo options page for your subsequent WordPress theme.

www.FeedBurner.com) 10 Resources to Help You Create a Killer WordPress Options Page

See strange here: 
10 Resources to Help You Create a Killer WordPress Options Page


Get Auto Caffeinated Content for Your WordPress Blog

Pages