The shortcodes system introduced by WordPress waaay back in version 2.5 was a great way of adding theme-specific styling through a simple-to-use tag in your post editor, or in your theme’s coding. The advantage of using short codes is to get the functionality with the limited number of codes. The same code can be used for inserting a functionality like chart, google maps etc. Today, we’ve released a plugin for Elgg 1.8 which will let Elgg users also to use the Shortcode functionality. Thanks to wordpress for providing the complete short code library.
You can download the plugin from our site, or Elgg community or the latest version under development from GitHub.
About the Plugin.
The plugin is inspired from WordPress shortcode system and it uses the same library for Elgg. The plugin comes default with some short codes like embed pdfs, google charts, maps, web page thumbnails, youtube links etc. You can easily embed these things in your post / comment contents just by adding it in a particular format like
- [embedpdf width=”600px” height=”500px” url=’http://infolab.stanford.edu/pub/papers/google.pdf’]
- [chart data=”41.52,37.79,20.67,0.03″ bg=”F7F9FA” labels=”Reffering+sites|Search+Engines|Direct+traffic|Other” colors=”058DC7,50B432,ED561B,EDEF00″ size=”488×200″ title=”Traffic Sources” type=”pie”]
- [googlemap width=”600″ height=”300″ src=”http://maps.google.com/maps?q=Heraklion,+Greece&hl=en&ll=35.327451,25.140495&spn=0.233326,0.445976& sll=37.0625,-95.677068&sspn=57.161276,114.169922& oq=Heraklion&hnear=Heraklion,+Greece&t=h&z=12″]
- [snap url=”http://www.webgalli.com” alt=”My description” w=”400″ h=”300″]
If you want to add your own shortcodes for example a simple Hello World text, You can do it in either of the following ways
Method 1.
- Create your own Elgg plugin
- In the init() function of your plugin add the following
elgg_add_shortcode('hellotext', 'my_hellotext_shortcode')
- Now declare the function in the same start.php before the php endtag (?>)
function my_hellotext_shortcode() { echo 'Hello World, this is my first short code'; }
Method 2.
- Open the mod/galliShortcodes/lib/galliShortcodes.php file in your favorite text editor and add the above two code snippets to it. Save it
PS : Although method two sounds easier, it is adviced to follow method one. Because this way your modifications will be preserverd even if you upgrade the galliShortcodes plugin. If you are following mthod 2, you can request us to include your additions in the code by creating pull requests. This will make the library more powerful and will be useful for yourself and others.
How to display the shorcode contents?
Ok, now we are ready to use our short code system. To output the short code just enter the following in your comments / post creation page
[hellotext]
Thats it.
Few suggestions : If you want to create shortcodes for display contents, place your css and js contents inside respective files located inside mod/galliShortcodes/views/default/galliShortcodes.
Sky is the limit with this plugin. Keep watching this space till for getting updates.
Tags: elgg charts, elgg map, elgg player, elgg shortcodes, elgg videos, elgg youtube, embed charts in elgg, embed maps in elgg, shortcodes for elgg
how to enable gallishortcodes on thewire and comment text area ? thanks you , for your help
to bad that the demo is offline and the video is near to silnet..great that you made all the plugins and documented them and even made screencasts about it.. but when no one can hear it is it nearly useless and a not working demo is not satisfying..when there’s no demo.. don’t put a demo link into the post..