Author visibility as hidden

I try to hide author visibility due to space limitations inside responsive design.
Just as a an example: John Dear

Visibility: J. D.
How to manage using existing PHP code?

<a href=""><?php echo $author = get_the_author(); ?></a>


<?php echo get_the_author($post->ID);?>

You can’t because the server has no idea of the browser, nor does it care. You’re going to need to do it via javascript.

If you’re insistent on a server side helper, you can change the get_the_author method to output two spans with classes, something like this

<span class="initial">JD</span><span class="fullName">John Dear</span>

Then have css which handles the classes appropriately

.initial { display:none; }
@media screen and (max-width: 480px) {
  .initial { display:inline-block; }
  .fullName { display: none; }

Maybe I am wrong but date can echo:

<?php echo get_the_date ('d. M  Y', $post->ID);?>

How to echo only Capitals like J. D. from John Deer

<a href=""><?php echo $author = get_the_author(); ?></a>

You’re missing my point. The server (i.e. PHP) has no idea what size the window of the browser calling it is, so there’s no way to determine which value to return.

This can only be done client side. You can control the client side one of two ways, through JavaScript or CSS.

To do it with CSS will require a change server side like I suggested above.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.