Title: Permalinks not working in plugin code
Last modified: August 20, 2016

---

# Permalinks not working in plugin code

 *  Resolved [ripperdoc](https://wordpress.org/support/users/ripperdoc/)
 * (@ripperdoc)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/permalinks-not-working-in-plugin-code/)
 * Hi, I am trying my luck modifying a plugin that pulls in external pages and inserts
   them as posts. What I want to achieve is to insert image links in an identical
   way as when you use the media uploader and press “Insert into post”.
 * After navigating through media.php in wp-admin/includes, I found a couple of 
   function doing this (it is done in many places with different code it seems).
   Most of them use the function get_attachment_link() for the URL to link the image
   to. However, when I run it in my code, it does not output permalinks, although
   permalinks are activated and are outputted when I insert an image manually into
   a post.
 * Does it have something do to with the code running before permalinks are initiated,
   or what is the context required for get_attachment_link() to work? (other permalink
   functions are also broken at that point in the running code).

Viewing 1 replies (of 1 total)

 *  Thread Starter [ripperdoc](https://wordpress.org/support/users/ripperdoc/)
 * (@ripperdoc)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/permalinks-not-working-in-plugin-code/#post-2219755)
 * Actually, found the issue: the plugin creates draft posts, and they are not given
   permalinks (although in the post editor, they are appearing with a permalink).
   Worth noting for others that if your plugin works with draft posts, permalink
   functions does not work.
 * I circumvented it with a filter that temporarily pretends a post is not in draft
   in order for it to get a permalink.

Viewing 1 replies (of 1 total)

The topic ‘Permalinks not working in plugin code’ is closed to new replies.

## Tags

 * [admin](https://wordpress.org/support/topic-tag/admin/)
 * [permalink](https://wordpress.org/support/topic-tag/permalink/)

 * 1 reply
 * 1 participant
 * Last reply from: [ripperdoc](https://wordpress.org/support/users/ripperdoc/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/permalinks-not-working-in-plugin-code/#post-2219755)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
