• Disclaimer: my PHP knowledge is very very basic.

    I have a child theme with a functions.php file in it. I don’t edit the parent functions.php at all however I want to override something. I can’t seem to do this w/o error though.

    Currently in the parent functions.php (among other things) is this:

    /**
     * Posts Meta Data. Category and Date.
    **/
    function ti_meta_data(){
    
    	global $ti_option;
    
    	// Category Name
    	if ( is_single() ) {
    		if ( $ti_option['single_post_cat_name'] == true ) {
    			echo '<span class="entry-category">'; the_category(', '); echo '</span>';
    		}
    	} else {
    		echo '<span class="entry-category">'; the_category(', '); echo '</span>';
    	}
    
    	// Date
    	$publish_date = '<time class="entry-date updated" datetime="' . get_the_time( 'c' ) . '" itemprop="datePublished">' . get_the_time( get_option( 'date_format' ) ) . '</time>';
    
    	if ( is_home() || is_front_page() || is_page() ) {
    		if ( $ti_option['home_post_date'] == 1 ) {
        		echo $publish_date;
    		}
    	}
    	if ( is_category() || is_tag() || is_author() ) {
    		if ( $ti_option['archive_post_date'] == 1 ) {
        		echo $publish_date;
    		}
    	}
    	if ( is_single() ) {
    		if ( $ti_option['single_post_date'] == 1 ) {
        		echo $publish_date;
    		}
    	}
    }

    I’d like to add the comment count before the categories because it’s missing for some reason. The theme does have it at the bottom where the comments are and so I can copy that php and add it to the meta_data function in functions.php:

    comments_number(__('No Comments', 'themetext'), __('1 Comment', 'themetext'), __( '% Comments', 'themetext') );

    However, how can do these changes in the child theme functions file without getting the error that this code already exists in the parent functions?

    Also, I need to add a span around the comment count so i can add a class to it. Not sure where to add that in.

    I am using SimpleMag theme

    Thanks in advance!

Viewing 1 replies (of 1 total)
  • Thread Starter marianney

    (@marianney)

    Since no one seems to know, I figured it out myself. In case anyone else has the same issue, here is what i did. I don’t know if its the best solution, but I added the comments link to the single.php instead of functions.php and added the span tags around the function:

    <span class="entry-comments"><a href="#comments"><?php comments_number(__('No Comments', 'themetext'), __('1 Comment', 'themetext'), __( '% Comments', 'themetext') ); ?></a> /</span>

    The link is a jump link to the comments section where i added this at the bottom of the single.php file:

    <a name="comments"></a>

    I’m sure there’s a more elegant solution, but it works.

Viewing 1 replies (of 1 total)
  • The topic ‘Add HTML inside a php function in functions.php’ is closed to new replies.