The [gv_entry_link] shortcode
You can place [gv_entry_link] on any post or page, or inside a View, to link to one entry. The link opens the entry’s Single Entry page by default, and the action attribute turns it into an edit or delete link.
In the block editor, the GravityView Entry Link block makes the same links, with the View, the entry and the action among its settings. It has no lightbox setting.
Note: Edit and delete links appear only for users who may edit or delete that entry: administrators, editors, and the person who created the entry. That person sees the edit link when the View has Allow User Edit turned on, and the delete link when it has Allow User Delete turned on. Everyone else sees nothing where the shortcode is.
When the View has an Edit Window, the creator’s edit link disappears once the window closes. Their delete link disappears too when Also apply to deleting entries is turned on. Administrators and editors keep both links.
Shortcode attributes #
| Attribute | What it does | Default |
|---|---|---|
view_id | The ID of the View that shows the entry. Required outside a View. | The View the shortcode is in |
entry_id | The ID of the entry. first and last pick the entry at the top or the bottom of the View’s list, in the View’s sort order. Required outside a View. | The entry the shortcode is in |
action | read links to the Single Entry page, edit links to Edit Entry, and delete deletes the entry. | read |
secret | The View’s secret. Required when the View has Enable Enhanced Security turned on, unless the shortcode is inside that View. | None |
post_id | The ID of a page or post that embeds the View. The entry then opens on that page. | The View’s own address |
lightbox | true opens the entry, or its Edit Entry form, in a lightbox. Delete links ignore it. | Off |
return | html returns a link, and url returns only the link’s address. | html |
link_atts | HTML attributes for the link, as name=value pairs joined by &. Ignored when return is url. | None |
field_values | Query parameters for the link’s address, as name=value pairs joined by &. | None |
Attribute values can contain the {get} merge tag. For example, entry_id="{get:member}" takes the entry ID from the page address, as in ?member=123.
Examples #
The examples use a View with the ID 2, an entry with the ID 123 and abc123 as the View’s secret, so replace each one with your own. Enable Enhanced Security: the secret attribute for shortcodes shows where to copy a View’s secret. New Views start with Enhanced Security turned on, and a View without it needs no secret.
Link to an entry
Put the link text between the opening and closing tags:
[gv_entry_link entry_id="123" view_id="2" secret="abc123"]View profile[/gv_entry_link]The shortcode returns this link:
<a href="https://example.com/view/team-directory/entry/123/">View profile</a>Without link text, end the shortcode with /] instead of a closing tag. The link then reads View Details, Edit Entry, or Delete Entry, depending on action.
[gv_entry_link entry_id="123" view_id="2" secret="abc123" /]Link to edit an entry
Set action="edit" to open the entry in Edit Entry:
[gv_entry_link action="edit" entry_id="123" view_id="2" secret="abc123"]Edit profile[/gv_entry_link]Link to delete an entry
Set action="delete":
[gv_entry_link action="delete" entry_id="123" view_id="2" secret="abc123"]Remove profile[/gv_entry_link]Before the entry is deleted, the browser asks the user to confirm with “Are you sure you want to delete this entry? This cannot be undone.”
After the deletion, the View’s Redirect After Deleting setting decides where the user goes. By default, that’s the View’s list of entries, which shows “The entry was successfully deleted.”
Use the shortcode inside a View
In a View’s Custom Content field, the shortcode links to the entry that the field belongs to, so it needs no view_id, entry_id, or secret. This adds an edit link to each entry the user may edit:
[gv_entry_link action="edit"]Edit profile[/gv_entry_link]Creating an “Edit Your Profile” link uses this to give each user a link to their own profile.
Link to a related entry in another View
Inside a View, entry_id can also take a field’s value. A Dynamic Lookup field saves the ID of an entry from another form, and its :id modifier gives that ID. This link opens each member’s department in a View of the Departments form with the ID 3:
[gv_entry_link entry_id="{Department:4:id}" view_id="3"]Department[/gv_entry_link]Without :id, the merge tag gives the department’s name, and the shortcode shows nothing. Add secret when the Departments View has Enhanced Security turned on. On an entry where the field is empty, the link opens a page with no entry.
With Connected Views in GravityView Pro, the field can make this link without a shortcode. Set its Link to setting to An entry in another View, choose the View, and each value links to its entry by name.
With Stay in this View, the entry opens with breadcrumbs and a Back link to the entry the visitor came from. Getting started with Connected Views explains the setting.
Open the entry on the page that embeds the View
By default, the link goes to the View’s own address (/view/…). When the View is embedded on a page, set post_id to that page’s ID so the entry opens there:
[gv_entry_link entry_id="123" view_id="2" post_id="45" secret="abc123" /]The link now points to the page:
<a href="https://example.com/members/entry/123/">View Details</a>The page ID is the number after post= in the address bar while you edit the page. Inside a View that is embedded on a page, add post_id as well, so the shortcode’s links open on that page like the View’s own links do.
When the View has Prevent Direct Access turned on, visitors get “Page not found” at its own address, so a link to it needs post_id.
Link to the first or last entry
Set entry_id to first to link to the entry at the top of the View’s list, or to last for the entry at the bottom. Both follow the View’s Sort by field and Sort direction in the Filter & Sort tab. A View left at Default (Entry ID) and Ascending lists the oldest entry first, so last links to the newest:
[gv_entry_link entry_id="last" view_id="2" secret="abc123"]Our newest[/gv_entry_link]Open the entry in a lightbox
Add lightbox="true" to open the entry in a lightbox over the current page:
[gv_entry_link entry_id="123" view_id="2" lightbox="true" secret="abc123"]View profile[/gv_entry_link]
With action="edit", the Edit Entry form opens in the lightbox:
[gv_entry_link action="edit" entry_id="123" view_id="2" lightbox="true" secret="abc123"]Edit profile[/gv_entry_link]When the View has Prevent Direct Access turned on, the lightbox opens the entry and its Edit Entry form on a page that embeds the View. On other front-end pages, visitors see “The requested entry could not be found.” in the lightbox, while administrators and editors still see the entry.
A lightbox link inside the View, such as one in a Custom Content field, also opens on the View’s page in the WordPress dashboard. Dashboard Views adds that page, and the lightbox opens there for every role the page lets in, such as Authors and Contributors chosen under Limit Access to User Role(s).
To link to the entry from another page, leave out lightbox and set post_id to the page that embeds the View.
To open a View’s own entry links in a lightbox, see Opening and editing entry details in a lightbox (modal/popup).
Open the link in a new tab
Use link_atts to add HTML attributes to the link, such as target=_blank to open it in a new tab:
[gv_entry_link entry_id="123" view_id="2" link_atts="target=_blank" secret="abc123" /]The shortcode adds rel="noopener noreferrer" to the link as well:
<a href="https://example.com/view/team-directory/entry/123/" rel="noopener noreferrer" target="_blank">View Details</a>Join more than one attribute with &. This link also gets the class button:
[gv_entry_link entry_id="123" view_id="2" link_atts="target=_blank&class=button" secret="abc123" /]Return only the address
With return="url", the shortcode returns the address without a link around it:
[gv_entry_link action="edit" entry_id="123" view_id="2" return="url" secret="abc123" /]The result looks like this:
https://example.com/view/team-directory/entry/123/?edit=4f1c9a2b7e&gvid=2The edit value is a security code made for the signed-in user.
Add values to the address
Use field_values to add query parameters to the link’s address:
[gv_entry_link entry_id="123" view_id="2" field_values="first-name=Maria" secret="abc123" /]It returns:
<a href="https://example.com/view/team-directory/entry/123/?first-name=Maria">View Details</a>On the Single Entry page, the {get} merge tag shows the value. For a worked example, see Using the {get} Merge Tags with [gvlogic] to display a person’s name in a Custom Content widget.
Fill empty fields in Edit Entry
With action="edit", field_values fills empty fields in the Edit Entry form:
- In the form editor, select the field and open the Advanced tab of its settings.
- Turn on Allow field to be populated dynamically and enter a Parameter Name, such as
department.
Then use the parameter names in field_values:
[gv_entry_link action="edit" entry_id="123" view_id="2" field_values="department=Sales&office=Berlin" secret="abc123"]Complete your profile[/gv_entry_link]A field that already holds a value keeps it. Gravity Forms explains parameter names in Dynamically Populating a Field.
When the link does not appear #
The shortcode shows nothing when:
- the user may not edit or delete the entry (edit and delete links only)
- the View’s Edit Window has closed for the person who created the entry (edit links, and delete links when Also apply to deleting entries is turned on)
- the shortcode is outside the View, the View has Enhanced Security turned on, and
secretis missing or wrong view_idorentry_idis missing and the shortcode is not inside a View- no entry has the ID in
entry_id - the View has Prevent Direct Access turned on, Connected Views opens it from another View, the shortcode has no
post_id, and the link is outside that View’s connected path. Inside the path, the link still works and opens the entry there.
For a missing or wrong secret, users who can edit the View, which by default means administrators, see a message in its place. It says the shortcode is missing or has an invalid “secret” attribute, and gives the attribute to add, such as secret="abc123".
The older edit and delete shortcodes #
[gv_edit_entry_link] works like [gv_entry_link action="edit"], and [gv_delete_entry_link] works like [gv_entry_link action="delete"]. They take the same attributes and still work, so pages that use them need no change.