Question

I want to create markdown style backtick shortcode...

...that replaces backtick pairs with a <span class="inline_code"></span> pair, but did not found how to achieve this without [] signs and without [/] closing tag. Same goes for ** to <strong></strong>.

Can you provide some links / examples for such a shortcode pattern? I'm happy with some other (non-shortcode) solitions as well if there is no other way.

Was it helpful?

Solution

By adding such content filters (to functions.php or below):

function add_markdown_tiny($content)
{
    $patterns = array
    (
        '/`([^\*]+)`/',
        '/\*\*([^\*]+)\*\*/'
    );

    $replacements = array
    (
        '<code>$1</code>',
        '<strong>$1</strong>'
    );

    $replaced = preg_replace($patterns, $replacements, $content);
    return $replaced;
}
add_filter( 'the_content', 'add_markdown_tiny', 10);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top