Toggles: PHP

Knowledgebase Docs » ShiftNav » API
Knowledgebase Docs » ShiftNav » Toggles
USEFUL? 4

PHP toggle tags are perfect for adding toggles in your theme templates.

/* Function definition */
function shiftnav_toggle( $target_id , $content = null, $args = array() )

To insert a toggle for the main ShiftNav panel, you would use this

<?php shiftnav_toggle( 'shiftnav-main' ); ?>

You can set the content of the toggle with the second parameter.

<?php shiftnav_toggle( 'shiftnav-main' , 'Open Sesame!' ); ?>

The third parameter takes an array of arguments which can be used to define an ID, element/tag, and additional classes to add to the toggle. For example, the following:

<?php 
shiftnav_toggle( 'shiftnav-main' , 'Open Sesame!' , array( 
     'id' => 'my-special-toggle',
     'el' => 'span',
     'class' => 'button' 
) ); ?>

would produce this markup:

<span id="my-special-toggle" class="shiftnav-toggle button" data-shiftnav-target="shiftnav-main">Open Sesame!</span>

Hint: Mobile visibility

By default this toggle will appear at all viewport widths. Want it to appear only below the same breakpoint as the main toggle bar? Add the shiftnav-toggle-mobile class to the toggle bar element

<?php 
shiftnav_toggle( 'shiftnav-main' , 'Open Sesame!' , array( 
     'class' => 'shiftnav-toggle-mobile' 
) ); ?>

Note that this visibility can be easily overridden by other CSS on your site, so if it is not working, check that you don’t have other CSS setting this to display:none;