簡體   English   中英

我在wordpress父主題中對模板文件進行了一些自定義更改。 如何確保主題更新時它們不會被覆蓋?

[英]I made some custom changes to template files in my wordpress parent theme. How do i make sure they are not overwritten when theme gets updated?

這是php模板中的代碼。 但這在我更新主題時將被覆蓋,因為更改是在主主題文件中進行的。

可以將這段代碼放在functions.php子主題文件中嗎? 還是我必須將模板文件復制到我的子主題中? 將來保留這些更改的最佳方法是什么? 所做的修改之一是下面的代碼,該代碼僅在我的單個列表頁面中根據用戶角色隱藏一個元素。

<?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>

希望對此有所幫助。

這是文件的屏幕截圖(如果需要),我不確定:

php文件

假設父主題使用get_template_part()函數來加載其部分/模板(如應這樣,例如, get_template_part( 'templates/single-listing/quick-actions/call-now' ); ),那么您需要做的所有事情將templates文件夾從父主題復制到子主題,然后在其中編輯call-now.php文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM