• Resolved Christine357

    (@christine357)


    Hey guys I am trying to change the following function just to reword how it displays the entry_meta for posts:

    function twentytwelve_entry_meta() {
    	// Translators: used between list items, there is a space after the comma.
    	$categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
    
    	// Translators: used between list items, there is a space after the comma.
    	$tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
    
    	$date = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>',
    		esc_url( get_permalink() ),
    		esc_attr( get_the_time() ),
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date() )
    	);
    
    	$author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
    		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    		esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
    		get_the_author()
    	);
    
    	// Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
    	if ( $tag_list ) {
    		$utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
    	} elseif ( $categories_list ) {
    		//$utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
    		$utility_text = __( '%3$s | by %4$s || in %1s' );
    	} else {
    		$utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
    	}
    
    	printf(
    		$utility_text,
    		$categories_list,
    		$tag_list,
    		$date,
    		$author
    	);
    }
    endif;

    I’ve learned in the past it is not as simple as paste the function into your child theme php file but the use of filters is required. I read the documentary after looking at a couple other functions I had help putting in before but I still don’t really understand what I need to do to make my change to the above function and so am hoping someone could help me out. 🙂 Eventually I’ll get it.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Christine357

    (@christine357)

    I know the change I want to make and how to do it within the function. All I am asking for is help how to put it in my functions.php of my child theme. I have to use filters don’t I? When I paste it in and make the change I want it errors the entire website when I update the file.

    Thread Starter Christine357

    (@christine357)

    Why was my post moved to Plugins and Hacks? I’m just trying to troubleshoot how to edit a functions.php file.

    @christine – I moved it to “Hacks” after your second post (which decreased your chances of being answered as it removed it from “No replies”) – no one had replied in “How To…” I’ll be happy to move it back if you’d prefer. (I’d also have answered it if I knew the answer – sorry I don’t.)

    Moderator bcworkz

    (@bcworkz)

    Hi Christine – WPyogi did you a favor. Whether you realize it or not, you are theme hacking, a topic right up my alley, and I don’t really spend much time in other forums.

    In PHP, you normally can’t re-define functions, which is in part why you need to use filters. As it happens, twentytwelve_entry_meta() is a “pluggable” function which is the only kind that you can re-define. Technically it’s not re-defined, but the concept is the same. So no need to hook into a filter with this particular function.

    I assume this code was placed in your child theme’s functions.php file? If so, you’ve used the correct approach and did what you’re supposed to do. And yet it breaks your site! Don’t worry, it happens to the best of us. You’ve just made a syntax error somewhere. If you haven’t, define WP-DEBUG as true in wp-config.php. This will cause error messages about what went wrong, and where, to be displayed.

    The error message can be cryptic sometimes, a general web search of the error description will usually help you understand. The location is very helpful, though sometimes the actual error is a few lines up, the line reported is where the parser realized there was a problem.

    If you still can’t figure out how to fix your code, post the error message here and we’ll see if we can get you set straight. It helps also if you indicate which line the error refers to since we don’t have access to your entire file.

    Happy debugging!

    Thread Starter Christine357

    (@christine357)

    @wpyogi my second reply was due to my post being pushed from the 1st page…which in my opinion decreases chance for reply even greater. But maybe there are people that scroll through additional pages searching for unanswered posts, who knows.

    Parse error: syntax error, unexpected T_ENDIF in (location on server)functions.php on line 71

    Above is the error I was receiving. I didn’t understand why it had a problem with the endif (I’m still a rookie with PHP and thought there was some need for it in this case after an if statement) so I went ahead and removed it to further see the issue and it worked. I looked back at the original code and had missed an if statement above

    if ( ! function_exists( 'twentytwelve_entry_meta' ) ) :

    that was wrapping the code I was using.

    Thank you bcworkz for the tip about wp-config and enabling it so I can see syntax errors.

    @wpyogi my second reply was due to my post being pushed from the 1st page.

    Yes, and that’s against the forum rules… http://codex.wordpress.org/Forum_Welcome#No_Bumping

    I was actually REALLY hoping that @bcworkz (awesome as always :)!) would see your thread here – YAY!!

    I expect the two of you will get this sorted in short order :)!

    Moderator bcworkz

    (@bcworkz)

    Glad that was sorted painlessly!

    For future reference: Wanting to be on the first page is a natural desire, but it’s a false benefit. The regulars here who are most likely to be able to help people specifically look for posts with no replies. It doesn’t have anything to do with what page you’re seeing your post on. We’re looking for people’s questions that have no answers yet. As soon as you bump your post, you fall off of our “radar”. Your additional posts make it appear that you’ve been helped by someone. You end up being ignored by the people in the best position to help you.

    So instead of drawing more attention to your question, you are actually increasing the chances it will be ignored. And it’s against the rules.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘twentytwelve_entry_meta() Change’ is closed to new replies.