Created
September 6, 2016 18:36
-
-
Save cogdog/864a698baada4af10b2737405d29890d to your computer and use it in GitHub Desktop.
Wordpress filter to convert copied Markdown
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
/* ----- change content on output as needed ----- */ | |
function stripFirstLine( $text ) { | |
// removes first line of text from string | |
// ----- h/t http://stackoverflow.com/a/7740485/2418186 | |
return substr( $text, strpos($text, "\n")+1 ); | |
} | |
add_filter( 'the_content', 'cc_cert_content_filter', 20 ); | |
function cc_cert_content_filter( $content ) { | |
if ( is_page_template( 'page-cert.php' ) ) { | |
// replace local links in markdown tp work as sub page links in WP | |
$content = str_replace ( '.md', '/', $content); | |
// replace all URLs for the repo image with one for GH pages (so we can link) | |
$content = str_replace ( 'https://github.com/creativecommons/cc-cert-map/blob/master/img/' , 'https://creativecommons.github.io/cc-cert-map/img/' , $content); | |
$content = do_shortcode('[siblings depth="1" class="topnav"]') . $content; | |
} elseif ( is_page_template( 'page-map.php' ) ) { | |
// remove first line that has # Header) | |
$content = stripFirstLine( $content ); | |
// replace all URLs for the repo image with one for GH pages (so we can link) | |
$content = str_replace ( 'https://github.com/creativecommons/cc-cert-map/blob/master/img/' , 'https://creativecommons.github.io/cc-cert-map/img/' , $content); | |
// set up shortcode stuff to prefix content, based on parent ID | |
$parent_id = wp_get_post_parent_id( get_the_ID() ); | |
// insert short codes | |
$content = do_shortcode('[pagelist child_of="' . wp_get_post_parent_id($parent_id) . '" depth="1" class="topnav"]') . do_shortcode('[modnav title="' . get_the_title($parent_id) . '" type="module"]') . $content; | |
} | |
// Send back the content, pronto! | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment