mercredi 25 mai 2016

How to add div's with variables into a wordpress function?

Hey all, I'm trying to add some div's with variables into a function. I know the html needs to be wrapped, what is the best way to do this? Here is the code I'm trying to add to a function.

    function add_before_sidebar( ) { 

    <div class="acro-sidebar-preview">
        <div class="acro-sidebar">
            <div class="image-container">
                <div id="profile-picture-preview" class="profile-picture" style="background-image: url(<?php print $picture; ?>)">
        </div>
    </div>
        <h1 class="acro-username"><?php print $fullname; ?></h1>
        <h2 class="acro-description"><?php print $description; ?></h2>
    <div class="icons-wrapper">

    <?php print '<a href="' . $twitter . '"><img src="' . plugins_url( 'img/twitter.png', __FILE__ ) . '" ></a>' ?>
    <?php print '<a href="' . $facebook . '"><img src="' . plugins_url( 'img/facebook.png', __FILE__ ) . '" ></a>' ?>
    <?php print '<a href="' . $google . '"><img src="' . plugins_url( 'img/googleplus.png', __FILE__ ) . '" ></a>' ?> 

        </div>
    </div>
</div>
}
add_action( 'get_sidebar', 'add_before_siderbar' );

All of the above code is connected to this set of variables I have setup

<?php
    $picture = esc_attr( get_option('profile_picture') ); 
    $firstname = esc_attr( get_option('first_name') );
    $lastname = esc_attr( get_option('last_name') );
    $fullname = $firstname . ' ' . $lastname; 
    $description = esc_attr( get_option('user_description') ); 
    $twitter = esc_attr( get_option('twitter_handler') );
    $facebook = esc_attr( get_option('facebook_handler') );
    $google = esc_attr( get_option('google_handler') );
    ?>

The code itself works great outside of the function. I'm familiar with writing a div with variable in a function but this is a bit more complex then I'm used to. Any help would be appreciated. Thanks in advance!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire