- This topic has 7 replies, 2 voices, and was last updated 5 years, 4 months ago by
Elvin.
-
AuthorPosts
-
December 15, 2020 at 2:18 am #1581156
ETO
Hello!
Here you can find two custom codes I need to use ininc/structure/archive.php: https://www.diffchecker.com/e7cgNx0qI would like to add these codes to the same file using Elements so that I can update the theme without having to add them manually each time.
I would be grateful if you could find a solution to this issue?
December 15, 2020 at 3:08 am #1581210Elvin
StaffCustomer SupportHi,
I’ve checked your code and a some part of it is from
<style>tag.Style tags can be placed anywhere so you don’t have to worry where you place them.
As for this:
<?php if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb( '<p id="breadcrumbs">','</p>' ); } ?>Place it inside a Hook Element and hook it on
generate_before_archive_titleand set the display rule to the page you want it to apply on.As for this:
<div style="width:100%;"> <?php $term = get_queried_object(); $term_id = $term->term_id; $taxonomy_name = $term->taxonomy; $termchildren = get_term_children( $term_id, $taxonomy_name ); echo '<ul>'; foreach ( $termchildren as $child ) { $term = get_term_by( 'id', $child, $taxonomy_name ); echo '<li><h2><a href="' . get_term_link( $term, $taxonomy_name ) . '">' . $term->name . '</a></h2></li>'; } echo '</ul> </br></div>'; ?>Place it inside another Hook Element and hook it on
generate_after_headerand set the display rule to the page you want it to apply on.December 15, 2020 at 4:21 am #1581285ETO
Thank you, Elvin.
If I do just as you wrote above, will there be any difference in terms of the place the breadcrumbs and the other code appear on my site?December 15, 2020 at 4:32 am #1581298Elvin
StaffCustomer SupportIf I do just as you wrote above, will there be any difference in terms of the place the breadcrumbs and the other code appear on my site?
For the contents of
<style>, you can actually place them within Appearance > Customize > Additional CSS if you don’t need display rule condition for it. No need to hook it if its not something you want conditions placed on.For the breadcrumbs, most users place them on the
generate_after_headerhook which comes right after the closing</header>tag but on your code, you placed it before thedo_action( 'generate_before_archive_title' );line so I just assumed you want to place it on thegenerate_before_archive_titlehook.If you read the file, there are actually clues as to which hook to best place things into. Look out for those
do_action,add_actionand the markup closing tags.December 15, 2020 at 1:20 pm #1582048ETO
Thank you so much, Elvin. I have successfully transferred the codes above to hooks.
However, there are several codes in a few files, which my theme developer added although I mentioned the hooks of GP theme.The next custom code is in the
content-single.phpfile: https://www.diffchecker.com/KjN2aGInI placed this code on both
generate_after_contentandgenerate_before_comments_containerhooks. But it breaks theme.What shall I do for this?
December 15, 2020 at 4:17 pm #1582184Elvin
StaffCustomer SupportThank you so much, Elvin. I have successfully transferred the codes above to hooks.
However, there are several codes in a few files, which my theme developer added although I mentioned the hooks of GP theme.If there are actually more codes than initially mentioned, it may be best to actually create a child theme. If your site developer made templates, then it may be best to just add it in along with the other child theme files.
Tip: Hooks Element is for presentation purpose. It’s for inserting tidbits of markups.
Add this CSS so the comments area wraps under the content area.
.site-content { display: flex; flex-wrap: wrap; }December 17, 2020 at 11:43 am #1584862ETO
Thanks, Elvin!
functions.php
header.php
archive.php
content-single.phpI have custom codes in the files I listed above. We couldn’t use child theme as there were some codes in
inc/structure/archive.phpfile and child theme supports only the files in the main directory of the theme. However, I managed to move the custom codes in this file to the hooks in elements thanks to your help.Now I wonder which method is better to choose, transfer the custom codes from the listed files above to hooks and the Snippets plugin OR use a child theme? What is the difference and which is better to use considering the future updates of the main theme, WordPress, plugins, etc?
December 17, 2020 at 3:43 pm #1585072Elvin
StaffCustomer SupportWe don’t recommend making changes to the default theme files as any changes made to them will be wiped once the theme updates.
Now I wonder which method is better to choose, transfer the custom codes from the listed files above to hooks and the Snippets plugin OR use a child theme?
Since you seem to be doing lots of changes so child theme is the way to go.
Code snippets is for general use of smaller, fewer snippets. Child theme is for multiple big changes like template editing(what you’re doing now).
-
AuthorPosts
- You must be logged in to reply to this topic.