2016-09-21 171 views
9

我只是想添加一个短代码按钮到我的wordpress主题菜单栏来处理bootstrap modal view函数。WordPress的导航栏中的自定义短代码

我试过'Shortcodes in Menus'插件,但它不起作用。我无法在菜单中找到短代码的替代插件,所以我安装了'Bootstrap 3 Shortcodes'插件,它创建了按钮和模式视图内容,如我所愿。但是我不能在我的菜单栏中添加简码。

我努力尝试找到一些关于我的问题的答案。但不幸的是,不能。

这就是我的模态短代码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] 

我只想用[modal text="Download Now" title="Veteriner Hekimlere Ulaşmanın En Kolay Yolu" xclass="btn btn-primary btn-lg"]WP导航栏。

我该怎么做?我可以在functions.php中为此写一个函数,或者尝试其他方法?

谢谢...

+0

你想从简码按钮到菜单项的样式? –

+0

我现在不在乎风格。我只想通过菜单栏项触发引导模式视图。 – emresancaktar

+0

你有没有请你也分享你的标记,你用你的短代码包装''[modal text =“立即下载”title =“Veteriner HekimlereUlaşmanınEn Kolay Yolu”xclass =“btn btn-primary btn-lg”]'? – mlbd

回答

0
function my_function_name($item_output) { 
    if(YOUR LOGIC FOR WHEN YOU WANT IT) 
     $item_output .= do_shortcode('[modal text="Download Now" title="Veteriner Hekimlere Ulaşmanın En Kolay Yolu" xclass="btn btn-primary btn-lg"]'); 

    return $item_output; 
} 
add_filter('wp_nav_menu', 'my_function_name', 10, 1); 
+0

嗨,它不起作用。警告:缺少my_function_name()的参数2,在第235行的/opt/bitnami/apps/wordpress/htdocs/wp-includes/plugin.php中调用,并在/ opt/bitnami/apps/wordpress/htdocs/wp-content中定义/themes/frexy/functions.php在线89 – emresancaktar

+0

我编辑了答案,尝试使用该版本的代码。 – Spartacus

+0

仍然是同样的错误 – emresancaktar

0

我不知道什么是结果提供这种短代码。在我的想法中,你可以看到一个按钮,当你点击然后显示模型窗口,并且你想在导航菜单上实现按钮。我没有测试这些代码,但如果这对您有帮助,您可以尝试。

首先创建一个新的php文件并将所有短代码内容放在那里。例如, my-modal.php

//my-modal.php 
[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] 

在你的主题function.php中创建一个新的函数并包含这个文件。

function modal_shortcode_content(){ 
    ob_start(); 
    include "my-modal.php"; 
    $shortcode_content = ob_get_content(); 
    ob_clean(); 
    return do_shortcode($shortcode_content); 
} 

在导航内容中添加短码输出。我不确定我认为短代码只提供按钮,而其他部分在您点击按钮时隐藏并可见。

function navigation_add_button_menu($item_output) { 
// apply any logic here... 
     $item_output .= modal_shortcode_content(); 

    return $item_output; 
} 

add_filter('wp_nav_menu', 'navigation_add_button_menu', 10, 1); 
2

如果您共享您的简码生成要与您的简码,这将是最好的给他人了解清楚包标记或做标记。

反正试试这个它会工作顺利(测试)

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; 
} 

随意改变你的菜单主题的位置。

希望它有道理。

0

你的代码很杂乱,我不能给你一个工作脚本,因为它是另一种语言,我不明白,我不想惹事。

反正,试试这个。这是一个简单的逻辑,通过简码获取你想要的内容。我用它在我的网站上。

function html_code() { 
    if(//Trigger Event Goes Here) { 
     // Use echo's to output the HTML of the window 
    } 
} 

function modal_window() { 
    html_code(); 

    return ob_get_clean(); 
} 

add_shortcode('modal_window');