How can I convert functions like the_permalink() into strings like $permalink?

1 Answer 1


Use get_permalink() function which returns a value instead of printing it.

Example -

$permalink = get_permalink($id); //$id if using outside loop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.