• Resolved zilla4

    (@zilla4)


    Hi I’m trying to set up my comment and edit buttons on posts to have an image next to them…

    this works:

    <?php edit_post_link('Edit »'); ?><img src="<?php echo bloginfo( 'template_directory' ) . '/images/edit.png'; ?>" width ="16" height="16" class="icon-edit">

    But my problem is when the post creator isn’t logged in you can still see the edit image but not the edit text…

    Can anyone explain to me the correct way of linking the edit icon to the “edit_post_link” code so that it disappears when not in use also??

    thanks

    thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • before printing edit button, check if user is logged in

    https://codex.www.ads-software.com/Function_Reference/is_user_logged_in

    Thread Starter zilla4

    (@zilla4)

    Hey! Thanks for that kkarpieszuk! This seems to be what I need but I’m not very good with PHP… I can’t figure out how use the image tags within the php… I keep breaking the code…

    can anyone help? I tried below but it does not work…

    <?php  if (is_user_logged_in()){
               echo"<img src='/images/edit.png' width ='16' height='16' class='icon-edit'">;
             }
             else {
               echo "";
               };
    ?>
    Thread Starter zilla4

    (@zilla4)

    ah figured it out!

    <?php  if (is_user_logged_in()){
               echo'<img src="https://www.brookeluder.com/wp-content/themes/default/images/edit.png" width ="16" height="16" class="icon-edit">';
             }
             else {
               echo "";
               };
    ?>

    you don’t need to write “else” statement. also i think you can change url

    <?php  if (is_user_logged_in()){
               echo'<img src="'.get_stylesheet_directory_uri().'/images/edit.png" width ="16" height="16" class="icon-edit">';
             }
    ?>

    this way it will be more flexible. if you will change domain, it will still work

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Icon for Edit button’ is closed to new replies.