[Resolved] Child theme

Home Forums Support Child theme

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1479738
    Joyce

    Hi Team,

    I modified GP theme PHP file (e.g. wp-content/themes/generatepress/comments.php) and every time I upgrade theme, I have to re-do all these changes. I have seen others using child theme, just wondering what is the right way to handle it. Can you pls help to confirm if my understanding is correct?

    1) add customized PHP code in child theme and set child theme as main theme (child theme code will overwrite default theme PHP)
    2) when upgrade GP theme, upgrade GP theme only, do not touch child theme

    Thanks,
    Joyce

    #1479879
    David
    Staff
    Customer Support

    Hi there,

    once the Child theme is installed.
    Copy the themes comments.php file into the Child Theme folder.
    Make your edits to the Child Themes comments.php

    Then you can safely update the Parent theme and keep your changes πŸ™‚

    #1488204
    Joyce

    Thanks David, sorry for my late reply.

    I follow https://docs.generatepress.com/article/using-child-theme/ and create my own child theme. However the following specific changes in child theme does NOT overwrite parent theme
    – /themes/generatepress_child/inc/structure/comments.php
    – /themes/generatepress_child/inc/structure/post-meta.php
    – /themes/generatepress_child/inc/theme-functions.php
    Only /themes/generatepress_child/comments.php works.

    I change inc folder permission to be 644 but it’s still the same. Is there a way to fix it?

    -rw-r--r--. 1 nginx nginx  2782 Oct 14 20:32 comments.php
    drwxr-xr-x. 3 nginx nginx  4096 Oct 14 20:32 inc
    -rw-r--r--. 1 nginx nginx 36593 Oct 14 20:32 screenshot.png
    -rw-r--r--. 1 nginx nginx   255 Oct 14 20:32 style.css
    

    into

    
    -rw-r--r--. 1 nginx nginx  2782 Oct 14 20:32 comments.php
    drw-r--r--. 3 nginx nginx  4096 Oct 14 20:32 inc
    -rw-r--r--. 1 nginx nginx 36593 Oct 14 20:32 screenshot.png
    -rw-r--r--. 1 nginx nginx   255 Oct 14 20:32 style.css
    
    #1488214
    Joyce

    inc and inc/structure files are shown below, thanks

    
    /wp-content/themes/generatepress_child/inc
    ll
    total 28
    drw-r--r--. 2 nginx nginx  4096 Oct 14 20:32 structure
    -rw-r--r--. 1 nginx nginx 23185 Oct 14 20:32 theme-functions.php
    cd structure/
    ll
    total 28
    -rw-r--r--. 1 nginx nginx  7040 Oct 14 20:32 comments.php
    -rw-r--r--. 1 nginx nginx 17011 Oct 14 20:32 post-meta.php
    
    #1488329
    David
    Staff
    Customer Support

    What changes are you trying to make to the Comments form? It may be possible to use filter hooks instead of overwriting the comments.php

    let me know.

    #1488369
    Joyce

    Hi David,

    Thanks for your reply. I am trying to do the followings

    1a) /inc/structure/comments.php
    – remove comment url/email input field (I tried to add in function.php and also generatepress/comments.php, but it does not work.

    add_filter('comment_form_default_fields', 'url_filtered');
    function url_filtered($fields)
    {
      if(isset($fields['url']))
       unset($fields['url']);
      return $fields;
    }
    add_filter('comment_form_default_fields', 'email_filtered');
    function email_filtered($fields)
    {
      if(isset($fields['email']))
       unset($fields['email']);
      return $fields;
    }

    1b) /inc/structure/comments.php
    – change text (leave a comment, Post Comment) and author label

    $defaults['title_reply'] = apply_filters( 'generate_leave_comment', __( 'Change text-Leave a Comment', 'generatepress' ) );
    $defaults['label_submit'] = apply_filters( 'generate_post_comment', __( 'Change text-Post Comment', 'generatepress' ) );
    <label for="author" class="screen-reader-text">Change text-author label</label>

    2) /inc/structure/post-meta.php
    – I need to display prev/next post link within one line, so I added css class (prev-post-link,next-post-link)

    <'previous_format' => '<div class="nav-previous prev-post-link">' . generate_get_svg_icon( 'arrow-left' ) . '<span class="prev" title="' . esc_attr__( 'Previous', 'generatepress' ) . '">%link</span></div>'
    <'next_format' => '<div class="nav-next next-post-link">' . '<span class="next" title="' . esc_attr__( 'Next', 'generatepress' ) . '">%link</span>' . generate_get_svg_icon( 'arrow-right' ) . '</div>'
    next-post-link {
    	float: right;
    	font-weight: bold;
    }
    .prev-post-link {
    	display: inline;  //div do not break into new line
    	font-weight: bold;
    }

    3) /inc/theme-functions.php (home page, open post in new tab)
    <h2 class="entry-title"%2$s><a href="%1$s" rel="bookmark" target="_blank">

    #1488969
    Leo
    Staff
    Customer Support

    By default, WordPress only allows the top-level files to be overwritten in a child theme – so that would only be these files you see here:
    https://github.com/tomusborne/generatepress

    I believe all 3 of your requirements can be done with filters and CSS though.

    Can you open a new topic for each of the requests?

    Thanks!

    #1489411
    Joyce
    #1489484
    Leo
    Staff
    Customer Support

    Thank you.

    We will get to them πŸ™‚

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.