WordPress.org

Ready to get started?Download WordPress

Forums

Modifying a function in a child php file (6 posts)

  1. BobWP
    Member
    Posted 1 year ago #

    I'm trying to add a function to a functions.php file in my child theme that removes the dates in Posts, and also removes "Posted on" preceding where the dates go.

    For the first part, I had success by adding a function from this web site:

    http://johnlamansky.com/wordpress/remove-post-dates/

    That worked. Then I added the function twentyeleven_posted_on() function from the parent theme functions.php file, removing "Posted on". This did work, however today when I tried to login to WP, I get a blank screen consistently. When I rename functions.php in the child theme, I'm able to log in. I'm not sure if my commenting is incorrect, or if it is something else.

    I'm not even sure my overall approach of bringing in the parent function and modifying it is correct, but that's what I've found so far. Thanks.

    functions.php follows:

    <!-- comment -->
    
    <?php
    
    /*
    This code removes the dates in Posts, but still leaves "Posted on"; so not a complete solution yet.
    */
    
    function jl_remove_post_dates() {
    	add_filter('the_date', '__return_false');
    	add_filter('the_time', '__return_false');
    	add_filter('the_modified_date', '__return_false');
    	add_filter('get_the_date', '__return_false');
    	add_filter('get_the_time', '__return_false');
    	add_filter('get_the_modified_date', '__return_false');
    } add_action('loop_start', 'jl_remove_post_dates');
    
    /*
    Remove "Posted on". Function from parent theme.
    */
    
    if ( ! function_exists( 'twentyeleven_posted_on' ) ) :
    /**
     * Prints HTML with meta information for the current post-date/time and author.
     * Create your own twentyeleven_posted_on to override in a child theme
     *
     * @since Twenty Eleven 1.0
     */
    function twentyeleven_posted_on() {
    	printf( __( '<span class="sep">  </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s" pubdate>%4$s</time></a><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'twentyeleven' ),
    		esc_url( get_permalink() ),
    		esc_attr( get_the_time() ),
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date() ),
    		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    		esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ),
    		get_the_author()
    	);
    }
    endif;
    
    ?>

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. Or better still - use the pastebin. As it stands, your code has been permanently damaged/corrupted by the forum's parser.]

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    is this

    <!-- comment -->

    part of your functions.php?

    if so, remove it, and also remove any space characters and/or empty lines before the first <?php in functions.php

    to get better error messages and warnings, consider to edit wp-config.php to allow DEBUG while you are customising your site:

    http://codex.wordpress.org/Editing_wp-config.php#Debug

  3. BobWP
    Member
    Posted 1 year ago #

    That html comment is above (thus outside of) the php open/close tags, but, yes, in the functions.php file. I thought I had it working with that comment in yesterday (and this is confounded by some earlier problems with the host), but after removing it, all seems OK now. Can html comments not be used in WP in php files if they are not inside the open/close php code?

    I'll try the debug tip.

    Most appreciated!

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    html comments will work fine outside of php in other templates, but functions.php is a sensitive file. Introducing any whitespace there will usually kill a site. You need to keep that opening php tag first and foremost.... within functions.php, best to stick to php comments

    <?php
    
    // single line comment
    
    /*
    Block
    comment
    */
  5. BobWP
    Member
    Posted 1 year ago #

    Rev. V., those are gems of information, that you so much!

  6. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    I'm glad you found that helpful!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.