Home › Forums › WoodMart support forum › Customize template with php code
Customize template with php code
- This topic has 20 replies, 3 voices, and was last updated 6 years, 5 months ago by Artem Temos.
-
AuthorPosts
-
August 17, 2018 at 8:21 am #73062
zeybixParticipantI modified the template with php code, specifically I modified the file “themes/woodmart/header-elements/logo.php”. How can I do to not lose the changes when I update the template?
August 17, 2018 at 9:10 am #73069
Elise NoromitMemberHello,
Copy your modification into woodmart-child/header-elements/logo.php
You can edit this files and in this case, you would not lose your changes.
Best Regards
August 17, 2018 at 10:57 am #73076
zeybixParticipantThat’s what I did, in this case I modified line 55 of the themes / miacactus-shop / inc / template-tags.php file and it does not work.
This same modification I do in the parent theme and if it works.
August 17, 2018 at 10:58 am #73077
zeybixParticipantThe php modification serves so that the content added in the description of the category file is not repeated in the pager.
August 17, 2018 at 11:11 am #73082
Artem TemosKeymasterYou can’t copy the file
inc/template-tags
to the child theme to override it. But you can take any PHP function from that file and paste tofunctions.php
in the child theme to modify it.August 17, 2018 at 11:28 am #73086
zeybixParticipantOk, thanks.
In other topics, if possible, copy files and wordpress, load the names of the child in the place of the parent theme.
In this case you can not by the template?
August 17, 2018 at 1:27 pm #73097
Artem TemosKeymasterYes, you can override standard wordpress template files like
header.php
,footer.php
etc. But you can’t override core PHP files with functions in any WordPress theme.August 17, 2018 at 4:53 pm #73128
zeybixParticipantOh ok, I was confused.
August 18, 2018 at 9:34 am #73167
Artem TemosKeymasterContact us if you will have any extra questions.
August 18, 2018 at 9:57 pm #73225
zeybixParticipantHello again,
I have done what you told me and everything is perfect, take the php file from the child theme.
However now I have another problem.
I have modified the logo.php file to set the logo image as H1 only for the home page. The problem is that it doubles 4 times. Now what I need is that I only put H1 the first time. Where is the logo.php file called for the first time? Or how could I get what I want to do?
Thanks
August 19, 2018 at 7:18 am #73234
Artem TemosKeymasterHi,
Could you please send us your source for this file so we can check what we can do there?
Thank you
August 19, 2018 at 9:58 am #73245
zeybixParticipantI attach the logo.php file. The modified code begins on line 27 and ends on line 42.
August 19, 2018 at 10:01 am #73246
zeybixParticipantI try to send the file changing the extension from php to txt.
Attachments:
You must be logged in to view attached files.August 19, 2018 at 10:07 am #73248
Artem TemosKeymasterTry to use this code
<?php global $logo_i; // Get the logo $logo = WOODMART_IMAGES . '/wood-logo-dark.svg'; $protocol = woodmart_http() . "://"; $has_sticky_logo = ( isset( $params['sticky_image']['url'] ) && ! empty( $params['sticky_image']['url'] ) ); if(isset($params['image']['url']) && $params['image']['url'] != '') { $logo = $params['image']['url']; } if(isset($params['image']['id']) && $params['image']['id'] != '') { $attachment = wp_get_attachment_image_src( $params['image']['id'], 'full' ); if( isset( $attachment[0] ) && ! empty( $attachment[0] ) ) $logo = $attachment[0]; } $logo = $protocol. str_replace(array('http://', 'https://'), '', $logo); $width = isset($params['width']) ? (int) $params['width'] : 150; $sticky_width = isset($params['sticky_width']) ? (int) $params['sticky_width'] : 150; ?> <div class="site-logo"> <div class="woodmart-logo-wrap<?php if( $has_sticky_logo ) echo " switch-logo-enable"; ?>"> <?php if(is_front_page() && ! $logo_i) { ?> <h1 class="logo-home-personalizado" title="Miacactus" alt="Miacactus shop"> <a href="<?php echo esc_url( home_url('/') ); ?>" class="woodmart-logo woodmart-main-logo" rel="home"> <?php echo '<img src="' . $logo . '" alt="' . get_bloginfo( 'name' ) . '" style="max-width: ' . esc_attr( $width ) . 'px;" />'; ?> </a> </h1> <?php $logo_i = true; }else{ ?> <a href="<?php echo esc_url( home_url('/') ); ?>" class="woodmart-logo woodmart-main-logo" rel="home"> <?php echo '<img src="' . $logo . '" alt="' . get_bloginfo( 'name' ) . '" style="max-width: ' . esc_attr( $width ) . 'px;" />'; ?> </a> <?php } ?> <?php if ( $has_sticky_logo ): ?> <?php $logo_sticky = $protocol . str_replace( array( 'http://', 'https://' ), '', $params['sticky_image']['url'] ); ?> <a href="<?php echo esc_url( home_url( '/' ) ); ?>" class="woodmart-logo woodmart-sticky-logo" rel="home"> <?php echo '<img src="' . $logo_sticky . '" alt="' . get_bloginfo( 'name' ) . '" style="max-width: ' . esc_attr( $sticky_width ) . 'px;" />'; ?> </a> <?php endif ?> </div> </div>
Regards
August 19, 2018 at 6:06 pm #73287
zeybixParticipantWith this modification, the H1 still appears twice.
You can see it at http://www.miacactus.com
August 19, 2018 at 8:49 pm #73295
Artem TemosKeymasterAs we can see, there is only one
h1
tag on that page.August 19, 2018 at 9:02 pm #73298
zeybixParticipantThere are two H1. See attached files.
August 19, 2018 at 9:04 pm #73299August 20, 2018 at 5:58 am #73326
Artem TemosKeymasterYou are right, the second H1 tag is located in the sticky header because it makes an exact copy of your main logo element and you can’t change it. Try to change the type of the sticky header and make only row with main navigation sticky to fix this problem. Read more information about these options in our documentation https://xtemos.com/docs/woodmart/header-builder/enable-sticky-header-option/
August 20, 2018 at 8:06 am #73350
zeybixParticipantBefore modifying the type of header I would like to understand how the template does it to see if I can give it a solution by php.
How does the logo copy in the stiky header? to do this, call the logo.php file twice From where?
August 20, 2018 at 8:53 am #73355
Artem TemosKeymasterHi,
It is not taken by PHP but by JS script in the file
js/functions.js
. So it just copies the HTML code for that element and uses in the sticky header.Regards
-
AuthorPosts
- You must be logged in to create new topics. Login / Register