duanduji2986 2019-05-11 14:32
浏览 86
已采纳

我在wordpress父主题中对模板文件进行了一些自定义更改。 当主题更新时,我如何确保它们不会被覆盖?

This is the code that is inside a php template. But this will be overwritten when i update the theme because the change is made in the mother theme files.

Is is possible to put this code inside the functions.php child theme file? Or do i have to copy the template files into my child theme? What is the best way to go about keeping these changes for the future? One of the modifications that is made is the code below which just hides an element based upon user-roles in my single listing page.

<?php
/**
 * `Call now` quick action.
 *
 * @since 2.0
 */

if ( ! ( $phone = $listing->get_field('phone') ) )
    return;

// if you want to not display anything for guests
if ( !is_user_logged_in() )
    return;

// if you want to not display anything for anyone but administrator or subscriber
$user = wp_get_current_user();
if ( !in_array( 'administrator', (array) $user->roles ) && !in_array( 'subscriber', (array) $user->roles ) ) 
    return;

$link = sprintf( 'tel:%s', $phone );
?>

<li id="<?php echo esc_attr( $action['id'] ) ?>" class="<?php echo esc_attr( $action['class'] ) ?>">
    <a href="<?php echo esc_url( $link ) ?>" rel="nofollow">
        <?php echo c27()->get_icon_markup( $action['icon'] ) ?>
        <span><?php echo $action['label'] ?></span>
    </a>
</li>

Would appreciate any help with this.

Here is a screenshot of the file if its needed, im not sure:

the php file

  • 写回答

1条回答 默认 最新

  • dongwei1895 2019-05-11 16:03
    关注

    Assuming the parent theme uses the get_template_part() function to load its partials/templates (as it should, eg. get_template_part( 'templates/single-listing/quick-actions/call-now' );), then all you need to do is copy the templates folder from your parent theme into your child theme and edit the call-now.php file there.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀