Skip to content

Instantly share code, notes, and snippets.

@szbl
Created June 30, 2009 15:52
Show Gist options
  • Save szbl/138224 to your computer and use it in GitHub Desktop.
Save szbl/138224 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Permalinker
Plugin Author: Andy Stratton
Plugin URI: http://theandystratton.com
Author URI: http://[email protected]
Version: 1.5
Description:
*/
// Example:
// [permalink id=123]My 123rd post![/permalink]
//
function permalinker_links($atts, $content = null) {
extract(shortcode_atts(array(
'id' => null,
'target' => null,
'class' => null,
'rel' => null
), $atts));
if ( empty($id) ) {
$id = get_the_ID();
}
$content = trim($content);
if ( !empty($content) ) {
$output = '<a href="' . get_permalink($id) . '"';
if ( !empty($target) ) {
$output .= ' target="' . $target . '"';
}
$output .= ' class="permalinker_link';
if ( !empty($class) ) {
$output .= " $class";
}
$output .= '"';
if ( !empty($rel) ) {
$output .= ' rel="' . $rel . '"';
}
$output .= '>' . $content . '</a>';
}
else {
$output = get_permalink($id);
}
return $output;
}
// Example:
// <img src="[template_uri]/images/my_inline_image.jpg" alt="Photo" />
//
function permalinker_template_uri( $atts, $content = null ) {
return get_template_directory_uri();
}
add_shortcode('permalink', 'permalinker_links');
add_shortcode('template_uri', 'permalinker_template_uri');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment