0

This is probably very unusual but I have a need to return a customizer setting value in functions.php to then pass into a function.

At the moment I'm trying this but the variable is empty. The customizer is set up correctly as I can get the value inside the theme files.

    $breakpoint = get_theme_mod( 'setting_navigation-breakpoint', '768' );

        function hn_add_inline_css($breakpoint) {
            $custom_css = '
                @media (min-width: ' . $breakpoint . 'px) {
                  .form-inline .form-group {
                    display: inline-block;
                    margin-bottom: 0;
                    vertical-align: middle;
                  }
                  ...

Is this even possible?

3
  • nothing unusual. Can you confirm you haven't saved the customizer before?
    – prosti
    Dec 13, 2016 at 13:27
  • Yeah I've saved it with a different value to the default
    – Brigante
    Dec 13, 2016 at 13:56
  • how you saved it?
    – prosti
    Dec 13, 2016 at 14:26

1 Answer 1

0

The solution was to get the customizer value inside the function, not passing the value to the function.

    function hn_add_inline_css() {
        $breakpoint = get_theme_mod( 'setting_navigation-breakpoint', '768' );

        $custom_css = '
            @media (min-width: ' . $breakpoint . 'px) {
              .form-inline .form-group {
                display: inline-block;
                margin-bottom: 0;
                vertical-align: middle;
              }
              ...
4
  • So what do you think made the difference?
    – prosti
    Dec 13, 2016 at 14:27
  • It doesn't seem like you can pass a variable to a function that you register through an add_action. add_action( 'wp_enqueue_scripts', 'hn_add_inline_css($breakpoint)' ); didn't work.
    – Brigante
    Dec 13, 2016 at 14:40
  • Yes, getting to the point add_action should set a function name and number of accepted arguments... as most important ,but in there you don't set the parameters. developer.wordpress.org/reference/functions/add_action
    – prosti
    Dec 13, 2016 at 14:46
  • please edit your question to set the details.
    – prosti
    Dec 13, 2016 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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