0
votes

I try to register a shortcode in Wordpress. To show the problem in a more simple way I use this code:

function moewe_readmore($atts, $content = null) {
    extract(shortcode_atts(array(
        'posts' => 1,
        'class' => '',
    ), $atts));

    $return_string = '<h4>'.$content.'</h4>';
    return $return_string;
}

add_shortcode( 'mrm', 'moewe_readmore' );

I add this shortcode to my theme:

<?php echo do_shortcode("[mrm]I am the Headline[mrm]"); ?>

But the output makes an empty "< h4 >" element and the Headline is placed alone in no html tag.

Thanks for you help.

1
you didn't close the shortcode with [/mrm] - DaFois

1 Answers

0
votes

It doesn't look like $content will contain anything, its currently set to null. I would also separate out the text "I am the Headline".

function moewe_readmore($atts, $content = null) {
    extract(shortcode_atts(array(
        'posts' => 1,
        'class' => '',
    ), $atts));

    $return_string = '<h4>'.$content.'</h4>';
    return $return_string;
}
add_shortcode('mrm', 'moewe_readmore');

Then you can just use this: <?php echo do_shortcode("[mrm]"); ?> I am the headline