Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom shortcode in Wordpress Nav Bar

I just want to add a shortcode button to my wordpress theme menu bar for handle the bootstrap modal view function.

I tried 'Shortcodes in Menus' plugin, but it doesn't work. I couldn't find alternative plugin for shortcodes in menu so I installed 'Bootstrap 3 Shortcodes' plugin, it created button and modal view content as i want. But I couldn't add shortcode to my menubar.

I did hard try to find some answer about my problem. But unfortunately could not.

Thats my modal shortcode generated by Bootstrap 3 Shortcodes plugin;

[modal text="Download Now" title="Veteriner Hekimlere Ulaşmanın En Kolay Yolu" xclass="btn btn-primary btn-lg"]
<p style="text-align: center;"><img src="http://web-test.vetmapp.com/wp-content/uploads/sites/2/2016/08/vetmapp-logo-withtext.png" alt="Logo" width="200" height="300" /></p>

<h4 style="text-align: center;">VetMapp'i cihazınıza göre aşağıdaki platformlardan cep telefonunuza ücretsiz olarak indirebilir ve hemen kullanmaya başlayabilirsiniz.</h4>
<p style="text-align: center;">
  <a href="https://itunes.apple.com/tr/app/vetmapp-acil-veteriner-klinikleri/id969463902?mt=8" target="_blank"><img src="http://web-test.vetmapp.com/wp-content/uploads/sites/2/2016/09/180x40xapple-store.png.pagespeed.ic.z0I7tHw8h6.png" alt="App Store'dan indir!" width="135" height="40" /></a>
  <a href="https://play.google.com/store/apps/details?id=com.esmobileinc.vetmapp&amp;hl=tr"
  target="_blank"><img src="http://web-test.vetmapp.com/wp-content/uploads/sites/2/2016/09/180x40xgoogle_play.png.pagespeed.ic.31v8JAmtbI.png" alt="Google Play'den indir!" width="135" height="40" /></a>
  <a href="https://www.microsoft.com/tr-tr/store/p/vetmapp/9nblggh4s3qm"
  target="_blank"><img src="http://web-test.vetmapp.com/wp-content/uploads/sites/2/2016/09/180x40xwindows_phone.png.pagespeed.ic.xvoiaCiuDP.png" alt="Windows Store'dan indir!" width="135" height="40" /></a>
</p>
[modal-footer] [button type="primary" style="border: solid 1px #18bda3; background-color: #fff; color: #18bda3;" link="#" data="dismiss,modal"]Kapat[/button] [/modal-footer] [/modal]

I just want to use [modal text="Download Now" title="Veteriner Hekimlere Ulaşmanın En Kolay Yolu" xclass="btn btn-primary btn-lg"] into WP Navigation Bar.

How can I do this ? I can write a function in functions.php for this, or try some another approach ?

Thank you...

like image 637
emresancaktar Avatar asked Sep 21 '16 09:09

emresancaktar


1 Answers

If you share your shortcode generate markup or what markup you want to wrap with your shortcode that would be best to others understand clearly.

anyway try this it will work smoothly (Tested)

add_filter( 'wp_nav_menu_items', 'wpse3967385_custom_menu_link', 10, 2 );

function wpse3967385_custom_menu_link( $items, $args ) {
   if ($args->theme_location == 'primary_nav') {
      $items .= '<li class="your-custom-item">' . do_shortcode( '[modal text="Download Now" title="Veteriner Hekimlere Ulaşmanın En Kolay Yolu" xclass="btn btn-primary btn-lg"]' ) . '</li>';
   }
   return $items;
}

Feel free to change your Menu theme location.

Hope it make sense.

like image 62
mlimon Avatar answered Sep 30 '22 14:09

mlimon