Search code examples
phpwordpresssyntaxapostrophe

Wordpress menu - <ul> with additional data


Hello i have problem with apostrophe when i want to add this in wordpress menu:

data-uk-scrollspy-nav="{closest:'li', smoothscroll:true}"

i want to menu looks like that:

   <ul class="uk-subnav" data-uk-scrollspy-nav="{closest:'li', smoothscroll:true}">
        <li class="uk-active"><a href="#getstarted">Get Started</a></li>
        <li class=""><a href="#templatesettings">Template Settings</a></li>
        <li class=""><a href="#customizer">Customizer</a></li>
        <li class=""><a href="#customization">Customizaton</a></li>
        <li class=""><a href="#troubleshooting">Troubleshooting</a></li>                               
    </ul>

so my wordpress code for it is:

<?php wp_nav_menu(
    array(
        'theme_location' => 'primary',
        'menu_class' => 'uk-navbar-nav uk-hidden-small',
        'menu_id' => 'main-menu',
        'items_wrap' => '<ul id="%1$s" class="%2$s" data-uk-scrollspy-nav="{closest:"li", smoothscroll:true}" >%3$s</ul>'
    )
); ?>

but i have this error:

Parse error: syntax error, unexpected 'li' (T_STRING), expecting ')' in /themes/dev/index.php on line 41

so the problem is apostrophe but i cant put quotation mark becouse script dont work.

anyone know how to resolve this problem??


Solution

  • Use the single quotes but escape them like so:

     'items_wrap' => '<ul id="%1$s" class="%2$s" data-uk-scrollspy-nav="{closest:\'li\', smoothscroll:true}" >%3$s</ul>'