Rob C. Watson
Rob C. Watson

Reputation: 13

Wordpress get_the_author function test not doing anything?

I'm trying to show the by-line of a Wordpress post only when it's a named author. I don't want to show the byline of the admin user.

Here's the code I'm using to attempt this:

<?php if (get_the_author() != 'admin')?> <h3 style="font-style:italic;">by <?php the_author(); ?></h3> <?php endif;?>

The behavior I'm seeing, but don't want, is that the page hangs up and displays only the header. It's only when I comment out the two php lines that the h3 content shows.

I've verified that the full string that would make the condition be true is exactly what I'm showing above. I copy/paste it from the view source of the rendered page. I've even tried using the number 1 both as an integer and as a character type for the test, but it still hangs the page.

What might I be doing wrong? Am I understanding this correctly?

Upvotes: 1

Views: 1233

Answers (1)

netcoder
netcoder

Reputation: 67715

Your problem, where the "page hangs up" is one of syntax. You are missing a : after your if statement:

<?php if (get_the_author() != 'admin')?>
                                      ^

This should fix it:

<?php if (get_the_author() != 'admin'): ?> <h3 style="font-style:italic;">by <?php the_author(); ?></h3> <?php endif;?>

This is the kind of error that is easily detectable by enabling error_reporting and checking your logs, or enabling display_errors as well:

error_reporting(E_ALL);
ini_set('display_errors', 1);

Upvotes: 1

Related Questions