Home Ask Login Register

Developers Planet

Your answer is one click away!

Josip Ivic February 2016

Wordpress as an endpoint

So, I'm building something and need to use wordpress as an endpoint.

I’ve a post url like http://example.com/sample-post. Now I’ve added a rewrite endpoint “edit”. So the url becomes http://example.com/sample-post/edit. Now whats the right way to print the url? Should it be like:

<?php echo get_permalink() . '/edit'; ?>

or is there any prefered way?


rnevius February 2016

Yes, that would be the preferred way. However, I recommend writing a function in functions.php to do some additional checks before printing the link:

function get_custom_edit_link() {
    // Check if we're on a Post page
    return is_single() ? get_permalink() . '/edit' : '';

And then in your template, call it with:

echo get_custom_edit_link();

However, if you're using this link to head to edit.php, you may want to consider using the get_edit_link() method of the WP_Posts_List_Table class.

Post Status

Asked in February 2016
Viewed 3,555 times
Voted 11
Answered 1 times


Leave an answer

Quote of the day: live life