Skip to content

Instantly share code, notes, and snippets.

@vienhoang
Created August 11, 2014 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vienhoang/c6f18ccb1cb52f16154c to your computer and use it in GitHub Desktop.
Save vienhoang/c6f18ccb1cb52f16154c to your computer and use it in GitHub Desktop.
WordPress: Custom shortcode
<?php
/*
Plugin Name: Twitter Shower
Plugin URI: http://vienhoang.com
Description: Display message.
Version: 1.0
Author: Vien Hoang
Author URI: http://vienhoang.com
License: GPL2
*/
// $content is between the shortcode
add_shortcode( 'twitter', function( $atts, $content ) {
$atts = shortcode_atts(
array(
'username' => 'vienhoang',
'content' => !empty($content) ? $conent : 'Follow me on Twitter!'
), $atts
);
// Extact the atts array and get variables from keys
extract($atts);
return "<a href=\"http://twitter.com/{$username}\">{$content}</a>";
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment