• Hi there,
    I am changing the theme on a site. The old theme used shortcodes which I am trying to reuse on the new theme. The shortcode in question is the following [learn_more caption=”text”][/learn_more]

    I’ve already managed to get the shortcode to no longer appear on the new theme, but the caption(?) attribute doesn’t appear on the new theme.

    Here is my code:

    
    function learn_more($atts, $content = null) {
        $default = array(
            'link' => '#',
        );
        $a = shortcode_atts($default, $atts);
        $content = do_shortcode($content);
        return $content;
    }
    add_shortcode('learn_more', 'learn_more');

    How do I make the text of the “caption” attribute appear as well?

    Thank you

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Add the caption attribute to the list of default-values:

    $default = array(
    		'link' => '#',
    		'caption' => 'my caption'
    	);
    	$a = shortcode_atts($default, $atts);

    In $a will be:

    array(2) { ["link"]=> string(1) "#" ["caption"]=> string(4) "text" }

Viewing 1 replies (of 1 total)
  • The topic ‘Shortcode’ is closed to new replies.