0

I am trying to do some edits to my parent theme. I have made a child theme so that updating the parent wont cause a problem.Now I want to add a certain function that is in the parent theme's functions.php to the functions.php file of the child theme. I am using Oblique theme. Here is the function from the parent file :

function oblique_post_link_to_single() {

    if ( ! get_theme_mod( 'read_more' ) ) :?>
        <a href="<?php the_permalink(); ?>">
            <div class="read-more">
                <?php echo apply_filters(
                      'oblique_post_read_more'
                    , esc_html__( 'Continue Reading &hellip;','oblique' )
                );?>
            </div>
        </a>
    <?php
    endif;

}

add_action( 'oblique_link_to_single','oblique_post_link_to_single' );

I tried pasting the code into the child theme but doing so gave me an http 500 error and crashed my website. I need to make some changes in this function inside the child theme and make sure this over rides the parent function.

  • what is the parent theme ? – mmm Oct 12 '17 at 13:07
1

You can't recall the same function or PHP will throw an error. Make your own function and call the same action hook, but give it a priority of 1 which should overrule the parent theme function.

function custom_oblique_post_link_to_single() { if ( ! get_theme_mod( 'read_more' ) ) :?> <a href="<?php the_permalink(); ?>"> <div class="read-more"> <?php echo apply_filters( 'oblique_post_read_more' , esc_html__( 'Continue Reading &hellip;','oblique' ) ); ?> </div> </a> <?php endif; add_action( 'oblique_link_to_single','custom_oblique_post_link_to_single', 1 );

  • A couple of other options here as well: mhthemes.com/support/… - or you can create a new function with your own name, and then override the parent theme wherever it calls the parent function so that in your child theme it calls the child function. Priority should be the easiest solution as you only have to edit functions.php and not every place the function is called. – WebElaine Oct 12 '17 at 13:58
  • I tried adding your code aswell but it's still throwing an error – Taaha Rauf Oct 12 '17 at 15:24
  • Found out the error an "{" was missing at the end another problem i am having that any changes made to this code does not appear which definitely means that the code is not being overridden – Taaha Rauf Oct 12 '17 at 16:12
  • I added a certain code in child theme using remove_action which removes the code from the parent theme that was causing the problem! Thanks for the help guys – Taaha Rauf Oct 12 '17 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.