Cara mengedit nilai variabel tema induk di tema anak di wordpress

Saya ingin mengubah nilai variabel tema Writee (Wordpress). Ada variabel di "content-post-header.php' bernama "$date_format" yang nilainya dikodekan sebagai "l, F j, Y" (variabel ini tidak ada dalam fungsi). Isinya adalah:

<?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="/id' . 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="/id<?php echo get_month_link(get_the_time('Y'), get_the_time('m')); ?>"><?php the_time($date_format); ?></a></span>
    </div>
</div>

Saya ingin mengganti variabel ini dan mengubah nilainya menjadi "l, j F, Y". Saya memiliki tema anak bernama Writee-child dan ada file function.php di sana yang seperti yang saya baca di forum, saya harus mengganti variabel di sana, tetapi dengan melakukan itu nilainya tidak berubah. misalnya, saya mencoba kode berikut:

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

tentu saja saya tidak tahu apa fungsi kodenya tetapi itu adalah hal paling relevan yang saya temukan di Google. Jadi, bagaimana cara mengubah nilai variabel ini?


person Amir Sh.    schedule 17.06.2017    source sumber


Jawaban (1)


Anda perlu membuat file di tema anak Anda dengan nama yang sama dengan file di tema induk. Dan letakkan file baru itu dalam struktur folder yang sama dengan file yang ada di tema induk. Dan di file baru Anda dapat mengubah kodenya.

<?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="/id' . 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="/id<?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