วิธีแก้ไขค่าตัวแปรของธีมหลักในธีมลูกใน WordPress

ฉันต้องการเปลี่ยนค่าตัวแปรของธีม Writee (Wordpress) มีตัวแปรใน "content-post-header.php' ชื่อ "$date_format" ซึ่งค่าของมันถูกฮาร์ดโค้ดเป็น "l, F j, Y" (ตัวแปรนี้ไม่ได้อยู่ในฟังก์ชัน) เนื้อหาคือ:

<?php 
/****************************************/
## Blog post header content.
/***************************************/

global $post;

$date_format = 'l, F j, Y';

?>
<div class="entry-header">
    <div class="entry-meta">
        <span class="entry-cat"><?php the_category(' ')?></span>
    </div>
    <?php 
    if (! is_single()) :
        the_title( '<h2 class="entry-title"><a href="/th' . esc_url( get_permalink() ) . '">', '</a></h2>' );

     else: 
        the_title( '<h1 class="entry-title">', '</h1>' );

    endif; 

   ?>
    <div class="entry-meta">
        <span class="entry-author"><?php echo __('By', 'writee'); ?> <?php the_author_posts_link(); ?> </span>
        <span class="entry-date"><?php echo __('on', 'writee'); ?> <a href="/th<?php echo get_month_link(get_the_time('Y'), get_the_time('m')); ?>"><?php the_time($date_format); ?></a></span>
    </div>
</div>

ฉันต้องการแทนที่ตัวแปรนี้และเปลี่ยนค่าเป็น "l, j F, Y" ฉันมีธีมลูกชื่อ Writee-child และมีไฟล์ function.php อยู่ที่นั่น ซึ่งตามที่ฉันได้อ่านในฟอรัม ฉันจะต้องแทนที่ตัวแปรที่นั่น แต่การทำเช่นนั้นค่าจะไม่เปลี่ยนแปลง ตัวอย่างเช่น ฉันลองใช้โค้ดต่อไปนี้:

function change_date_format(){ 
  global $date_format;
  $date_format = 'l, j F, Y';
}
add_action( 'after_setup_theme', 'change_date_format' );

แน่นอนฉันไม่รู้ว่าโค้ดนี้ทำอะไร แต่มันเป็นสิ่งที่เกี่ยวข้องมากที่สุดที่ฉันพบใน Google แล้วฉันจะเปลี่ยนค่าตัวแปรนี้ได้อย่างไร?


person Amir Sh.    schedule 17.06.2017    source แหล่งที่มา


คำตอบ (1)


คุณต้องสร้างไฟล์ในธีมลูกของคุณด้วยชื่อเดียวกับไฟล์ในธีมหลัก และวางไฟล์ใหม่นั้นไว้ในโครงสร้างโฟลเดอร์เดียวกันกับไฟล์ที่อยู่ในธีมหลัก และในไฟล์ใหม่คุณสามารถเปลี่ยนรหัสได้

<?php 
/****************************************/
## Blog post header content.
/***************************************/

global $post;

$date_format = 'what you want';

?>
<div class="entry-header">
    <div class="entry-meta">
        <span class="entry-cat"><?php the_category(' ')?></span>
    </div>
    <?php 
    if (! is_single()) :
        the_title( '<h2 class="entry-title"><a href="/th' . esc_url( get_permalink() ) . '">', '</a></h2>' );

     else: 
        the_title( '<h1 class="entry-title">', '</h1>' );

    endif; 

   ?>
    <div class="entry-meta">
        <span class="entry-author"><?php echo __('By', 'writee'); ?> <?php the_author_posts_link(); ?> </span>
        <span class="entry-date"><?php echo __('on', 'writee'); ?> <a href="/th<?php echo get_month_link(get_the_time('Y'), get_the_time('m')); ?>"><?php the_time($date_format); ?></a></span>
    </div>
</div>
person Vital388    schedule 17.06.2017