Created
September 8, 2018 18:37
-
-
Save davidwolfpaw/0baa572e4757bb2c41ac59f88a2cafce to your computer and use it in GitHub Desktop.
This is a custom shortcode to allow the link to a post while using the Genesis Framework for WordPress
This file contains hidden or 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 | |
/* | |
* This is a custom shortcode to allow the link to a post while using the Genesis Framework. | |
* | |
* It was created to fill the need of a loop that needed links to posts. | |
*/ | |
add_shortcode( 'post_link', 'genesis_post_link_shortcode' ); | |
/** | |
* Produces a link to the post with custom text. | |
* | |
* Supported shortcode attributes are: | |
* after (output after link, default is empty string), | |
* before (output before link, default is empty string), | |
* link_text (output text of link, default is 'Read More …') | |
* | |
* Output passes through 'genesis_post_link_shortcode' filter before returning. | |
* | |
* @param array|string $atts Shortcode attributes. Empty string if no attributes. | |
* @return string Return output for `post_link` shortcode. | |
*/ | |
function genesis_post_link_shortcode( $atts ) { | |
$defaults = array( | |
'link_text' => 'Read More …', | |
'before' => '', | |
'after' => '', | |
); | |
$atts = shortcode_atts( $defaults, $atts, 'post_link' ); | |
$link = get_the_permalink(); | |
if ( genesis_html5() ) { | |
$output = $atts['before'] . sprintf( '<a href="%s">%s</a>', $link, $atts['link_text'] ) . $atts['after']; | |
} else { | |
$output = $atts['before'] . '<a href="' . $link . '">' . $atts['link_text'] . '</a>' . $atts['after']; | |
} | |
return apply_filters( 'genesis_post_link_shortcode', $output, $atts ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment