Created
March 3, 2013 17:39
-
-
Save EricBusch/5077151 to your computer and use it in GitHub Desktop.
Create your own WordPress Permalink shortcode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Creates a shortcode that links to other | |
* content on your site. | |
*/ | |
function my_permalink_shortcode($atts) { | |
// Check that $id exists. | |
$id = intval($atts['id']); | |
if ($id <= 0) { return; } | |
// Check that $id has a URL. | |
$url = get_permalink($id); | |
if ($url == '') { return; } | |
// Get link option and title. | |
$link = ($atts['link'] == '1') ? true : false; | |
$title = (trim($atts['title']) == '') ? get_the_title($id) : $atts['title']; | |
// Determine if we create a link. | |
if ($link) { | |
return '<a href="'.$url.'">'.$title.'</a>'; | |
} else { | |
return $url; | |
} | |
} | |
add_shortcode('pl', 'my_permalink_shortcode'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment