I made Social Links for Author bio Now, I want to make a condition that whenever Social is added, the <ul class="social-area social-area-2"> </ul> class should be created. If no Social is added, the social-area social-area-2 class should not be added. Thank you for helping me

code file author-bio.php


    $facebook  = get_the_author_meta('facebook', $author_id);
    $twitter = get_the_author_meta('twitter', $author_id);
    if ( (bool) get_the_author_meta( 'description' ) && (bool) get_theme_mod( 'show_author_bio', true ) ) : ?>
    <div class="author-area">
    <div class="media">
        <?php echo get_avatar( get_the_author_meta( 'ID' ), 120 ); ?>

        <div class="media-body align-self-center">
            <div class="text-author">
                    <a class="author-link"
                        href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
                        <?php printf(get_the_author() ); ?>
                <?php echo wp_kses_post( wpautop( get_the_author_meta( 'description' ) ) ); ?>

            <ul class="social-area social-area-2">

                if(!empty($facebook)) {
                echo '<li><a title="Follow me on Facebook" href="'.$facebook.'"><i class="fab fa-facebook-f"></i></a></li>'; }

                if(!empty($twitter)) {
                echo '<li><a title="Follow me on Twitter" href="'.$twitter.'"><i class="fab fa-twitter"></i></a></li>'; }

<?php endif; ?>

code file functions.php

    function my_new_contactmethods( $contactmethods ) {

    $contactmethods['facebook'] = 'Facebook';
    $contactmethods['twitter'] = 'Twitter';
    return $contactmethods;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.