Created
September 7, 2012 00:17
-
-
Save tomharrigan/3661766 to your computer and use it in GitHub Desktop.
Typography shortcode with line-height addition in order to achieve leading. To use: [typography font=" " size=" " height=" " color=" "] [/typography]
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
| function woo_shortcode_typography ( $atts, $content = null ) { | |
| global $google_fonts; | |
| // Get just the names of the Google fonts. | |
| $google_font_names = array(); | |
| if ( count( $google_fonts ) ) { | |
| foreach ( $google_fonts as $g ) { | |
| $google_font_names[] = $g['name']; | |
| } // End FOREACH Loop | |
| } // End IF Statement | |
| // Build array of usable typefaces. | |
| $fonts_whitelist = array( | |
| 'Arial, Helvetica, sans-serif', | |
| 'Verdana, Geneva, sans-serif', | |
| '|Trebuchet MS|, Tahoma, sans-serif', | |
| 'Georgia, |Times New Roman|, serif', | |
| 'Tahoma, Geneva, Verdana, sans-serif', | |
| 'Palatino, |Palatino Linotype|, serif', | |
| '|Helvetica Neue|, Helvetica, sans-serif', | |
| 'Calibri, Candara, Segoe, Optima, sans-serif', | |
| '|Myriad Pro|, Myriad, sans-serif', | |
| '|Lucida Grande|, |Lucida Sans Unicode|, |Lucida Sans|, sans-serif', | |
| '|Arial Black|, sans-serif', | |
| '|Gill Sans|, |Gill Sans MT|, Calibri, sans-serif', | |
| 'Geneva, Tahoma, Verdana, sans-serif', | |
| 'Impact, Charcoal, sans-serif' | |
| ); | |
| $fonts_whitelist = array(); // Temporarily remove the default fonts. | |
| $defaults = array( 'font' => 'Arial, Helvetica, sans-serif', 'size' => '12', 'height' => '14', 'color' => '#000000', 'size_format' => 'px' ); | |
| extract( shortcode_atts( $defaults, $atts ) ); | |
| // Run checks to make sure it's an allowed font stack. | |
| if ( in_array( $font, $fonts_whitelist ) || in_array( $font, $google_font_names ) ) { | |
| if ( in_array( $font, $google_font_names ) ) { | |
| $font = "'" . $font . "'"; | |
| } // End IF Statement | |
| } else { | |
| $font = 'Arial, Helvetica, sans-serif'; | |
| } // End IF Statement | |
| // $font = str_replace( '|', '"', $font ); | |
| return '<span class="shortcode-typography" style="font-family: ' . $font . '; font-size: ' . $size . $size_format . '; line-height: ' . $height . $size_format . '; color: ' . $color . ';">' . do_shortcode( $content ) . '</span>'; | |
| } // End woo_shortcode_typography() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment