- This topic has 8 replies, 3 voices, and was last updated 3 years, 6 months ago by Leo.
-
AuthorPosts
-
October 9, 2020 at 12:33 am #1479738Joyce
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 themeThanks,
JoyceOctober 9, 2020 at 2:21 am #1479879DavidStaffCustomer SupportHi 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.phpThen you can safely update the Parent theme and keep your changes ๐
October 14, 2020 at 3:09 am #1488204JoyceThanks 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
October 14, 2020 at 3:14 am #1488214Joyceinc 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
October 14, 2020 at 4:56 am #1488329DavidStaffCustomer SupportWhat 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.
October 14, 2020 at 5:19 am #1488369JoyceHi 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">
October 14, 2020 at 10:20 am #1488969LeoStaffCustomer SupportBy 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/generatepressI 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!
October 14, 2020 at 4:36 pm #1489411JoyceOctober 14, 2020 at 6:14 pm #1489484LeoStaffCustomer SupportThank you.
We will get to them ๐
-
AuthorPosts
- You must be logged in to reply to this topic.