Last active
October 24, 2017 13:46
-
-
Save ChuckMac/4557026 to your computer and use it in GitHub Desktop.
Simple WordPress shortcode for adding dymanic links to pages/posts
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
function pagelink_shortcode( $atts ) { | |
extract(shortcode_atts(array( | |
'page' => '', | |
'title' => '', | |
'class' => '' | |
), $atts)); | |
$link = get_permalink($page); | |
if ($class != '') { | |
$class = ' class="'. $class . '"'; | |
} | |
return '<a href="' . $link . '" title="' . $title . '"' . $class . '>' . $title . '</a>'; | |
} | |
add_shortcode('pagelink', 'pagelink_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
[pagelink page="8" title="Link Title" class="link-class"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍