• I have a parent theme and a child theme. Everything is fine as long as I only make changes to “first level” php files like header.php or footer.php and the css.

    But here’s what I can’t figure out:
    I’ve made change to this file: parenttheme/includes/posts/custom-functions.php

    If I just add the edited custom-functions.php to my child-theme folder nothing happens. How to I get the theme to use my edited php-file?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Do you have a functions.php file in your Child Theme?

    Thread Starter Ligefrem

    (@ligefrem)

    No – havn’t made any changes to that one, so that’s just using the parent theme’s file.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Your theme should be checking to see if functions exist before using them. You should be able to just create a function (in your Child Theme functions.php file) with the same name as the one you want to override, and then make your modification in that function you’ve just created.

    Thread Starter Ligefrem

    (@ligefrem)

    I tried that, but got an error because the function already excisted. But I might have done it the wrong way. I’m not a programmer. Is this what is supposed to be in the functions.php?

    <?php
    	/***************
    	PROJECTS
    	***************/
    
    	function vires_portfolio_list() {
    		global $post, $portfolio_page_url;
    		if(get_option('vires_portfolio_hide')!="true") {
    			?>
    				<!--PROJECTS-->
    				<section class="home-projects">
    					<div class="inside project-block clear">
    						<h2><?php if(get_option('vires_hportfolio_header')!="") { echo get_option('vires_hportfolio_header'); } else { _e( 'Featured Work', LABOR_THEME_NAME ); } ?></h2>
    						<a href="https://buschagency.dk/authors/" class="view-all">
    							<?php if(get_option('vires_portfolio_link')!="") { echo get_option('vires_portfolio_link'); } else { _e( 'View All', LABOR_THEME_NAME ); } ?>
    						</a>
    
    						<div class="horScroll">
    							<ul class="clear">
    								<?php
    									$album_order = get_option('vires_album_order');
    									$album_orderby = get_option('vires_album_orderby');
    									$album_limit = get_option('vires_num_hportfolio');
    
    									$args = array( 'post_type' => 'portfolio', 'orderby' => $album_orderby, 'order' => $album_order, 'posts_per_page' => $album_limit, 'meta_query' => array( array( 'key' => 'exclude', 'value' => 'on', 'compare' => '!=' ) ) );
    									$wp_query = new WP_Query( $args );
    									while ($wp_query->have_posts()) : $wp_query->the_post();
    										?>
    											<li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    												<div class="pimage">
    													<a href="<?php the_permalink(); ?>" target="_blank">
    														<?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?>
    													</a>
    													<div class="project-mask">
    														<a href="<?php the_permalink(); ?>">
    															<?php if(get_option('vires_item_link')!="") { echo get_option('vires_item_link'); } else { _e( 'View Project', LABOR_THEME_NAME ); } ?>
    														</a>
    													</div>
    												</div>
    												<h5>
    													<?php the_title(); ?>
    													<?php if( function_exists('zilla_likes') ) zilla_likes(); ?>
    												</h5>
    											</li>
    										<?php
    									endwhile;
    								?>
    							</ul>
    						</div>
    					</div>
    				</section>
    			<?php
    		}
    	}
    ?>
    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Which theme is this?

    Thread Starter Ligefrem

    (@ligefrem)

    A theme called “The Vires”

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Thread Starter Ligefrem

    (@ligefrem)

    It’s from ThemeForest so it’s not there.

    I’ve had the issue several times with other themes too. As soon as something is in a subfolder I can’t get the child theme to override the parent theme. I’m probably just doing something wrong.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    https://wordpress.stackexchange.com/questions/55865/why-to-check-if-function-doesnt-exists-in-functions-php

    Can you request to the theme developer to use an “if function exists” check and release for the next theme update?

    Then you can modify your “parenttheme/includes/posts/custom-functions.php” and add the “if function exists” check yourself so you can work in your Child Theme function with the same name.

    Thread Starter Ligefrem

    (@ligefrem)

    Trouble is he doesn’t seem to be responding to support. Is there anything I can do?

    Other than the stupid solution to just overwrite the parents custom-functions.php

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    You can add the “if function exists” check to the customs-functions.php file in your parent theme for now. If the theme author doesn’t implement your request then when the theme updates your “if function exists” check will be erased and you’ll likely get a fatal error saying “cannot redeclare function” from your Child Theme function that has the same name.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Linking additional .php files to child theme’ is closed to new replies.