Markdown Parser To WordPress Site

Markdown Parser To WordPress Site

Markdown Parser To WordPress Site


This will give you the ability to use a markdown style field

Plugins Used

Advanced Custom Fields

Create a textarea field named markdown

Hooks functions.php

<?php
// html enitities before saving to database for markdown field
add_filter('acf/update_value/key=field_5a93080349e5a', 'before_acf_save', 10, 3);
function before_acf_save($value, $field, $post_id) {
    $value = htmlentities($value);
    return $value;
}
// html decode enitities when loaded from database for markdown field
add_filter('acf/load_value/key=field_5a93080349e5a', 'after_acf_load', 10, 3);
function after_acf_load($value, $post_id, $field) {
    $value = html_entity_decode($value);
    return $value;
}
Classes Used

Parsedown

In your theme file

<?php
if($markdown = get_field('markdown')) {
    echo '<hr />';
    include get_parent_theme_file_path('/custom/Parsedown.php');
    $parsedown = new Parsedown();
    $parsed = $parsedown->text($markdown);
    echo $parsed;
}
else {
    //for testing purposes
    //echo 'no markdown';
}