WordPress.org

Ready to get started?Download WordPress

Forums

Linking additional .php files to child theme (12 posts)

  1. Ligefrem
    Member
    Posted 8 months ago #

    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?

  2. Andrew
    Forum Moderator
    Posted 8 months ago #

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

  3. Ligefrem
    Member
    Posted 8 months ago #

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

  4. Andrew
    Forum Moderator
    Posted 8 months ago #

    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.

  5. Ligefrem
    Member
    Posted 8 months ago #

    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="http://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
    		}
    	}
    ?>
  6. Andrew
    Forum Moderator
    Posted 8 months ago #

    Which theme is this?

  7. Ligefrem
    Member
    Posted 8 months ago #

    A theme called "The Vires"

  8. Andrew
    Forum Moderator
    Posted 8 months ago #

  9. Ligefrem
    Member
    Posted 8 months ago #

    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.

  10. Andrew
    Forum Moderator
    Posted 8 months ago #

    http://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.

  11. Ligefrem
    Member
    Posted 8 months ago #

    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

  12. Andrew
    Forum Moderator
    Posted 8 months ago #

    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.

Reply

You must log in to post.

About this Topic