WordPress.org

Ready to get started?Download WordPress

Forums

child theme function.php override or remove parent theme function (3 posts)

  1. Phil-ip
    Member
    Posted 1 year ago #

    I have recently installed Reverie theme framework, which a versatile HTML5 Responsive WordPress Framework based on the Foundation framework.

    Im trying to replace the following function (in reverie):

    function reverie_entry_meta() {
    	echo '<time class="updated" datetime="'. get_the_time('c') .'" pubdate>'. sprintf(__('Posted on %s at %s.', 'reverie'), get_the_time('l, F jS, Y'), get_the_time()) .'</time>';
    	echo '<p class="byline author vcard">'. __('Written by', 'reverie') .' <a href="'. get_author_posts_url(get_the_author_meta('ID')) .'" rel="author" class="fn">'. get_the_author() .'</a></p>';
    }

    Using this function (in the child theme function.php)

    if (!function_exists('reverie_entry_meta')) {
    	function reverie_entry_meta() {
    		echo '<time class="updated" datetime="'. get_the_time('c') .'" pubdate>'. sprintf(__('%s at %s.', 'reverie'), get_the_time('l, F jS, Y'), get_the_time()) .'</time>';
    		echo '<p class="byline author vcard">'. __('Written by', 'reverie') .' <a href="'. get_author_posts_url(get_the_author_meta('id')) .'" rel="author" class="fn">'. get_the_author() .'</a></p>';
    	}
    }

    This does not work. I could modify the parent function.php, but that defeats the purpose of the reason for using a child theme - so that is not an option.

    How do I get this to work?
    Thank you for your time and your help.

  2. photocurio
    Member
    Posted 6 months ago #

    The solution is not so hard. If the parent theme contains a function that begins with:
    if (!function_exists('reverie_entry_meta')) {
    then you simply add this:
    function reverie_entry_meta() {};
    to your child theme's functions.php.

  3. Phil-ip
    Member
    Posted 6 months ago #

    Thank you photocurio!
    I guess that way of handling the parent function would be transferable to other child themes as well? Just to make sure that I understand the code, are you creating an empty function in the childthemes function.php?

    Thank you for your time and help!

Topic Closed

This topic has been closed to new replies.

About this Topic