Support » Themes and Templates » Twenty Eleven child theme functions.php trouble

  • Resolved inezxtan

    (@inezxtan)


    Hi everyone, I’d like to override some code in Twenty Eleven’s functions.php using a child theme I just created. However, anything but a totally empty child theme functions.php (with just the php open and close tags) crashes the site.

    Here’s what I want to override:

    http://ojcpcd.com/browse-articles/most-recent/ Just below the title of each post, where it says “Posted on (date) by (user)”

    As far as I can tell, the code is contained in the parent functions.php:

    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">Posted on </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 class="url fn n" 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;

    Any help would be very much appreciated, and I’d also gladly take more advice on child themes (I’ve read the WordPress documentation and a number of sites on Google, but keep crashing stuff anyway. :P). Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Michael

    (@alchymyth)

    Forum Moderator

    please post an example of your functions.php (any which is crushing your site).

    http://codex.wordpress.org/Child_Themes#Using_functions.php

    make sure that your functions.php starts with just:

    <?php

    Here’s one thing I tried, copied straight out of the Twenty Eleven functions.php. It seems like having the exact same thing in both functions.php breaks the site with good reason, but I also tried changing ‘twentyeleven_posted_on’ and all the twentyelevens to ‘ava’ (the name of my child theme):

    <?php
    
    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">Posted on </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 class="url fn n" 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;
    
    ?>

    I have read that particular codex entry and am afraid I still don’t know what exactly to do. Should I modify the parent functions.php first?

    Michael

    (@alchymyth)

    Forum Moderator

    what is the exact error message?

    your posted code alone in a functions.php in the child theme does not lead to an error.

    When I save that code, the page freezes and goes completely white, and none of my site will load. I have to go reset wp-options and change the template and css to something other than my child theme to unfreeze the site.

    Never mind – I’ve been a little more careful and I’m generally good. Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Twenty Eleven child theme functions.php trouble’ is closed to new replies.