• So I am writing an “Edit This” for my theme and I have a strange issue. Here is how the code currently looks:

    <?php global $user_ID; if($user_ID and current_user_can('level_1')) : ?>
    <!-- Displays an "Edit This Post" if user can edit it -->
    <a href="<?php echo(get_edit_post_link()); ?>" class="urdaedit">Edit This Post</a>
    <?php else: ?><?php endif; ?>

    But if you use:

    <a href="<?php get_edit_post_link(); ?>" class="urdaedit">Edit This Post</a>

    The second piece of code just shows the blog URL (https://www.domain.com/), while the first one correctly links the “Edit This” post for editing.

    Why is this?

Viewing 1 replies (of 1 total)
  • I can’t find any documentation of get_edit_post_link() here, but I just ran into the same problem. As near as I can tell, get_edit_post_link() does not echo itself. This is similar to the other “get” functions in WordPress. For example, get_page_ID() does not echo, but the_ID() does echo. So whenever you use a get_something() call in WP you have to remember to echo it yourself.

    The reason the second case above leaves you with a link to the blog URL is simply because the result of the get_edit_post_link() call was blank, so the URL ended link ended up being href=”” which ends up pointing back at whatever page you are sitting on.

    I just spent an hour trying to find the bug in my code and forgot this was a “get” call. This is so easy to overlook. I wish WP were less convoluted sometimes. Your post saved me! Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘get_edit_post_link – Echo Works, but Direct Link Fails’ is closed to new replies.