Skip to content

Instantly share code, notes, and snippets.

@SimonMayerhofer
Last active December 14, 2018 18:40
Show Gist options
  • Save SimonMayerhofer/50df6a969bc4fb7a8d251ca014366e9e to your computer and use it in GitHub Desktop.
Save SimonMayerhofer/50df6a969bc4fb7a8d251ca014366e9e to your computer and use it in GitHub Desktop.
PDF Download Element WordPress Shortcode - see it in action here: https://codepen.io/maysi/pen/aPNZbV
<?php
/**
* Adds shortcode for PDF download element.
*
* @package your-package.
*/
/**
* Add shortcode function for PDF download element.
* [pdf_download name="Aktuelle Produktinformationen" label="PDF DOWNLOAD" link="#"].
*
* @param array $atts attributes.
*/
function pdf_download_sc_func( $atts ) {
$atts = shortcode_atts(
array(
'name' => 'Aktuelle Produktinformationen',
'label' => 'PDF DOWNLOAD',
'link' => '#',
),
$atts,
'pdf_download'
);
ob_start();
?>
<a class="pdf-download" href="<?php echo esc_url( $atts['link'] ); ?>" target="_blank" rel="noopener">
<img class="pdf-download__icon" src="<?php echo esc_url( get_stylesheet_directory_uri() ); ?>/img/pdf-icon.svg" alt="PDF Icon">
<div class="pdf-download__text">
<span><?php echo esc_html( $atts['name'] ); ?></span><br>
<strong><?php echo esc_html( $atts['label'] ); ?></strong>
</div>
</a>
<?php
return ob_get_clean();
}
add_shortcode( 'pdf_download', 'pdf_download_sc_func' );
.pdf-download {
display: flex;
text-decoration: none;
color: #111;
align-items: center;
&:hover,
&:active,
&:focus {
color: #123b8b;
strong {
text-decoration: underline;
}
}
&__icon {
width: 50px;
}
&__text {
line-height: 1.5;
padding-left: 15px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment