Skip to content

Instantly share code, notes, and snippets.

@ChuckMac
Last active October 24, 2017 13:46
Show Gist options
  • Save ChuckMac/4557026 to your computer and use it in GitHub Desktop.
Save ChuckMac/4557026 to your computer and use it in GitHub Desktop.
Simple WordPress shortcode for adding dymanic links to pages/posts
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');
[pagelink page="8" title="Link Title" class="link-class"]
@Erutan409
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment