I created a text field in a shortcode for highcharts where we can choose a footer label for the chart. This is the field:

            'label' => esc_html( 'Footer label' ),
            'description' => esc_html( 'Choose the footer label' ),
            'attr' => 'footer_caption',
            'type' => 'text',

Until here its all good, the field is created and its saving the value i put in there and its in the database too. Example of the rendered html and what shows up in the database:

<input type="text" class="regular-text" name="footer_caption" id="shortcode-ui-footer_caption-c42" value="test caption" placeholder="">


[the_chart chart="23" footer_caption="test caption"/]

The problem is that i cant get the value of the field. In this chart for eg: test caption

Im not very used to PHP but i tried in a bunch of different ways to retrieve the value on footer_caption but with no luck. Im gonna have to pass that value in another function, so can someone help me out and tell me how i can retrieve the value of footer_caption?

1 Answer 1

    add_shortcode('the_chart ', 'high_chart');
        function high_chart($atts, $content = null) {
           //extract the cart and footer_caption value 
            extract(shortcode_atts(array( 'chart' => null, 'footer_caption' => null), $atts));
               * process your chart and footer_caption value as
               * $chart and $footer_caption and return the process data
            $return_html = 'chart id:'. $chart.'<br/> Footer Caption:'. 
            return $return_html


For reference: https://codex.wordpress.org/Function_Reference/add_shortcode Hope that you understand!

  • Your code works great, but I'm surprised WordPress uses such ugly syntax.
    – PJ Brunet
    Oct 10, 2019 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.