Home Forums WoodMart support forum Customize template with php code

Customize template with php code

Viewing 21 posts - 1 through 21 (of 21 total)
  • Author
    Posts
  • #73062

    zeybix
    Participant

    I 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?

    #73069

    Hello,

    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

    #73076

    zeybix
    Participant

    That’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.

    #73077

    zeybix
    Participant

    The php modification serves so that the content added in the description of the category file is not repeated in the pager.

    #73082

    Artem Temos
    Keymaster

    You 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 to functions.php in the child theme to modify it.

    #73086

    zeybix
    Participant

    Ok, 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?

    #73097

    Artem Temos
    Keymaster

    Yes, 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.

    #73128

    zeybix
    Participant

    Oh ok, I was confused.

    #73167

    Artem Temos
    Keymaster

    Contact us if you will have any extra questions.

    #73225

    zeybix
    Participant

    Hello 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

    #73234

    Artem Temos
    Keymaster

    Hi,

    Could you please send us your source for this file so we can check what we can do there?

    Thank you

    #73245

    zeybix
    Participant

    I attach the logo.php file. The modified code begins on line 27 and ends on line 42.

    #73246

    zeybix
    Participant

    I try to send the file changing the extension from php to txt.

    Attachments:
    You must be logged in to view attached files.
    #73248

    Artem Temos
    Keymaster

    Try 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

    #73287

    zeybix
    Participant

    With this modification, the H1 still appears twice.

    You can see it at http://www.miacactus.com

    #73295

    Artem Temos
    Keymaster

    As we can see, there is only one h1 tag on that page.

    #73298

    zeybix
    Participant

    There are two H1. See attached files.

    #73299

    zeybix
    Participant

    capture

    Attachments:
    You must be logged in to view attached files.
    #73326

    Artem Temos
    Keymaster

    You 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/

    #73350

    zeybix
    Participant

    Before 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?

    #73355

    Artem Temos
    Keymaster

    Hi,

    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

Viewing 21 posts - 1 through 21 (of 21 total)