Remove Author Information from Twenty Sixteen Theme

Even though the default WordPress theme is highly customizable, there are many things which you cannot directly change. For example, every post will show the author name and gravatar next to it on the left hand side as shown here:

author info showing

Solutions on the net for removing this only focus on hiding it using CSS using something like this:

.author {
    display: none;
}

While this solution works, the information is still visible in the page source code. To truly remove author information from Twenty Sixteen, we have to stop it from being generated in the first place. And CSS cannot help us with this. In this tutorial, I’m going to show you how to completely remove all author related information from the page so that it’s not visible even in the page source.

Overriding a Core Twenty Sixteen Function

To do this, we need to override a core Twenty Sixteen theme function known as twentysixteen_entry_meta(). The original location of this function is in /wp-content/themes/twentysixteen/inc/template-tags.php:

function in template tags php

Looking at the source code, we can create our own modified function without the parts that generate the author information. You can view the actual source code of the twentysixteen_entry_meta() function on github. Here’s what we need to paste into our functions.php file:

function twentysixteen_entry_meta() {

	if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) {
		twentysixteen_entry_date();
	}
	$format = get_post_format();
	if ( current_theme_supports( 'post-formats', $format ) ) {
		printf( '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>',
			sprintf( '<span class="screen-reader-text">%s </span>', _x( 'Format', 'Used before post format.', 'twentysixteen' ) ),
			esc_url( get_post_format_link( $format ) ),
			get_post_format_string( $format )
		);
	}
	if ( 'post' === get_post_type() ) {
		twentysixteen_entry_taxonomies();
	}
	if ( ! is_singular() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
		echo '<span class="comments-link">';
		comments_popup_link( sprintf( __( 'Leave a comment<span class="screen-reader-text"> on %s</span>', 'twentysixteen' ), get_the_title() ) );
		echo '</span>';
	}
}

Note that you cannot place this code in a custom plugin! Normally, I always recommend pasting PHP code into a custom plugin instead of functions.php. But if you try and paste the above snippet into a plugin, you’ll get a fatal error saying that you cannot redeclare it because it’s already declared.

cannot redeclare

This will only work when pasted into Twenty Sixteen’s functions.php file. You can learn how to do that from my earlier tutorial on pasting code snippets into WordPress. Of course, it’s equally important for you to create a child theme of Twenty Sixteen and modifying the the child’s functions.php instead of the original. This is because your changes will simply get overridden whenever the WordPress team releases a newer version of the theme.

So after you’ve created a child theme and pasted the above code into the child’s functions.php, you should see that the author information has vanished as shown here:

Remove Author Information from Twenty Sixteen

You can check and see that this information has vanished not just from the visible page, but also from the source. This is important if your goal is to post without anyone finding out the name of the author for whatever reason. A simple CSS fix might be easy, but doesn’t solve the main problem. Only overriding the primary function itself will remove author information from Twenty Sixteen.

 

Comments

  1. Thanks for sharing this. I have tried in putting this code my child’s php but it the author info is still there. Not sure what I did wrong. Also in my back-end if see this ‘%3$s’ above my site screen. Think something is not right
    Hope you can help me out.
    Many thanks,
    Hazy

    Reply

    • WPTweaks Admin says:

      It’s going to be tough to debug from here. You can introduce some “echo” statements into parts of the function to see if the code is being executed or not. Make sure your child theme is activated, and you’ve inserted the code into functions.php of your child them etc etc.

      It should work if all goes well…

      Reply

      • Not sure what ‘echo’ statements are and how I should use it. The child theme is activitated that’s for sure and I did put into fuction.php of the child.
        I got the below error:
        Error 400

        website.nl
        Thu Nov 24 09:27:12 2016
        Apache

        And the content of my php is as follows:

        get(‘Version’)
        );
        }
        add_action( ‘wp_enqueue_scripts’, ‘my_theme_enqueue_styles’ );
        ?>

        /* remove meta dat */

        function twentysixteen_entry_meta() {

        if ( in_array( get_post_type(), array( ‘post’, ‘attachment’ ) ) ) {
        twentysixteen_entry_date();
        }
        $format = get_post_format();
        if ( current_theme_supports( ‘post-formats’, $format ) ) {
        printf( ‘%1$s%3$s‘,
        sprintf( ‘%s ‘, _x( ‘Format’, ‘Used before post format.’, ‘twentysixteen’ ) ),
        esc_url( get_post_format_link( $format ) ),
        get_post_format_string( $format )
        );
        }
        if ( ‘post’ === get_post_type() ) {
        twentysixteen_entry_taxonomies();
        }
        if ( ! is_singular() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
        echo ”;
        comments_popup_link( sprintf( __( ‘Leave a comment on %s’, ‘twentysixteen’ ), get_the_title() ) );
        echo ”;
        }
        }

        Hope you can help.

        Thanks,
        Hazy

        Reply

        • WPTweaks Admin says:

          Ah, I see. Could you make sure that your file starts with the tag:

          < ?php It should be the very first thing in the file before everything else. Also, remove this code at the top: get(‘Version’) ); } add_action( ‘wp_enqueue_scripts’, ‘my_theme_enqueue_styles’ ); ?>

          Try it out and let me know if it works!

          Reply

          • I have below code in my child php. But stil error . I got this : %3$s. Above my site. This is part of your code. Maybe something is wrong or broke in your coding

            get(‘Version’)
            );
            }
            add_action( ‘wp_enqueue_scripts’, ‘my_theme_enqueue_styles’ );
            ?>

            function twentysixteen_entry_meta() {

            if ( in_array( get_post_type(), array( ‘post’, ‘attachment’ ) ) ) {
            twentysixteen_entry_date();
            }
            $format = get_post_format();
            if ( current_theme_supports( ‘post-formats’, $format ) ) {
            printf( ‘%1$s%3$s‘,
            sprintf( ‘%s ‘, _x( ‘Format’, ‘Used before post format.’, ‘twentysixteen’ ) ),
            esc_url( get_post_format_link( $format ) ),
            get_post_format_string( $format )
            );
            }
            if ( ‘post’ === get_post_type() ) {
            twentysixteen_entry_taxonomies();
            }
            if ( ! is_singular() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
            echo ”;
            comments_popup_link( sprintf( __( ‘Leave a comment on %s’, ‘twentysixteen’ ), get_the_title() ) );
            echo ”;
            }
            }

            Reply

          • WPTweaks Admin says:

            I see you still have the initial part starting with get(‘Version’) and ending with ?> . That’s not part of the code snippet. Can you replace that entire block with < ?php as suggested earlier, and let me know the results?

            Reply

          • This is strange. I did have my codes started with <?php ….. . I thought I didnt copy the codes correct to your reply box the first time. But this time I double checked whether I copied all the codes from my php and I did. So parts of the codes got removed after I send reply. It might be easier if I mail it directly to your email address instead of through this reply box.

            Reply

  2. Can you please tell me how to do it for
    CPMAGZ – A Magazine Theme By Code Themes.

    Reply

Speak Your Mind

*