0

I will frequently add a line of text in my article sending the reader to the article page. This is separate from the actual produced permalink. The problem I'm having is that I can't get the permalink until the article is posted. I can copy the text from the displayed permalink, but if the title is too long that won't work. I can also copy that permalink but then I just get the generic ?p=123 type of link and I have to be sure to remove the 'preview' part of it.

Is there a nifty piece of code to put in the link field that will pull the permalink for that article? Kind of how it does in the PHP? This would also solve the issue if the permalink was changed and it broke the custom link.

3 Answers 3

0

I would customize the Read More tag (natively built into WordPress).

Instead of producing your own URL, this tag will render the permalink for you. If you want to customize the text that appears here you can follow these specific instructions as well.

function modify_read_more_link() {
    return '<a class="more-link" href="' . get_permalink() . '">Your Read More Link Text</a>';
}
add_filter( 'the_content_more_link', 'modify_read_more_link' );
1
  • I do have the rendered "Full Story" button at the bottom, I was just wanting to put in an additional link of my own for added direction.
    – Chuck
    Jun 1, 2017 at 22:07
0

You might see Get Post Permalink and Get Permalink.

You'd probably want to combine this with a custom shortcode. All of your code would go in your functions.php file, or you can make a plugin and put it there.

0

I was able to find a solution to this with this custom function for shortcode:

https://www.thewebtaylor.com/articles/wordpress-display-permalinks-in-posts-using-shortcode

I just tested it and it worked great! Thanks for the direction guys!

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.