最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

customization - Need to replace some text string on a title

programmeradmin1浏览0评论

we are using Bridge theme in Wordpress as a basis for a restaurant menu. This menu has titles of food that in the plugin template (restaurant-menu-list-item.php) are called to be printed on the screen like this:

<div class="qode-rml-title-holder">
                <<?php echo esc_attr($restaurant_menu_item_title_tag)?> class="qode-rml-title">
                    <?php esc_html(the_title()); ?>
                </<?php echo esc_attr($restaurant_menu_item_title_tag)?>>
            </div>

We want to have icons together with the titles so that if we write a food name called "Chicken Stew [veryspicy]" that part that is marked "[veryspicy]" becomes two small icons of chili (png image).

We have made this code below and it works in WP body text but not in this part of the restaurant menu. We wonder if the "esc_html(the_title());" somehow blocks it or what is the reason.

//Spicy marks in the menu
function replace_text_wps($text){
    $replace = array(
        // 'WORD TO REPLACE' => 'REPLACED WITH THIS'
        '[spicy]' => '<img alt="Hot food" src=".png" style="width: 31px; height: 25px;">',
        '[veryspicy]' => '<img alt="Very hot food" src=".png" style="width: 31px; height: 25px;"><img alt="Very hot food" src=".png" style="width: 31px; height: 25px;">'
    );
    $text = str_replace(array_keys($replace), $replace, $text);
    return $text;
}

add_filter('the_content', 'replace_text_wps');

This code we have put into the functions.php of the theme. Tried to also to put it in the restaurant menu plugin file but the menu stopped to work like that. So, it does work on the website on a normal page as a body text but it doesn't work inside this restaurant menu plugin that prints the title and the description of the food from a form filled in the admin. How could we get it working?

发布评论

评论列表(0)

  1. 暂无评论