Here’s one way within the main loop on the attachment’s page:
First we get the parent ID from the current attachment’s post:
$parent_id = get_post_field( 'post_parent' );
Then we check if it’s non-zero and print the link to the parent:
if ( $parent_id ) {
printf(
'<a href="https://wordpress.stackexchange.com/questions/312468/%1$s">%2$s</a>',
esc_url( get_permalink( $parent_id ) ),
esc_html__( 'Go to parent', 'wpse' )
);
}
Hope you can expand this to your needs!
Related Posts:
- Disable Attachment Pages Completely
- How to add a class to the attachment images
- Adding Featured Image to Post programatically
- Add custom field to attachments in a specific category
- Conditional Statement – check if post has an attachment image
- Upload images and attachments from frontend form
- Get a Page’s attachments in Gallery order
- Use Timber/Twig to pull an image by image ID [closed]
- File upload, uploads only file name
- page template for attachement page?
- is it possible to force wordpress to always save thumbnails as ‘jpg’ not ‘png’
- WordPress Search Results for Multiple Post Types
- Send multiple attachments with wp_mail in PHP
- Attach previously uploaded image to post – current code has unexpected results
- wp_mail file attachment not being placed in upload folder?
- Returning data instead of echoing/printing
- Find out last 7 days of upload images, last week uploaded image from Gallery and display them in different pages
- How to get the filename from file system and create a download link?
- how to get attached file url for current post?
- Front end file upload returning wrong attachment url
- Attaching images to posts manually (i.e. with custom code, without the use of an API)
- How to load previous or next attachment with jquery ?
- Add class to all img if they have a certain ACF field
- Problem with inserting multiple images in gallery of each WooCommerce product programmatically
- Unable to delete related media attachments with deleted post
- Attach and retrive multiple pdf files to post or page
- Get list of posts from attachment
- Get posts associated with media attachment
- File path for attachments outside of wp-content/uploads
- Attachments doesn’t update
- Post Title Not showing up
- Target all images that are not the first attachment
- Correct Syntax for uploading files to custom directory in WordPress
- How to declare a global variable in php?
- Undefined variable in functions.php file [closed]
- load/require specific php files for specific pages/templates/post types
- Activate different theme for temporary preview
- Execute a shortcode when clicking on a image
- Store loop into array
- Add a custom text field to WooCommerce admin product data “Variations”
- Show Specific Footer Widget for Specific Pages
- How do I output a database option that is an array into a get_posts array?
- Why is it necessary to prevent direct access to included files?
- Run a Parallel PHP Application with WordPress
- Display Post co-authored in Author Page
- How can I use a $wp_customize to edit my homepage image slider?
- Password protecting content in custom template
- Creating login session via CURL
- woocommerce registration form with klaviyo(don’t work with current user)
- How to get a list of all possible values of a specific user meta key?
- Use object in template part
- Customizer – Prefix Class Extension
- Create onClick Event to Re-load a Widget
- Output Buffering – Everything between wp_head and wp_print_footer_scripts?
- functions.php is being included twice, creating PHP fatal errors
- Menu Limitations
- selected option if current category is the value
- Search Query: how to construct a search string from two select elements?
- Is it possible to retrieve all posts with a certain value for metadata?
- How to hook code to show after the_content?
- Run a code only on theme activation only during first activation
- Creating WordPress Shortcode with Variable
- Catchable fatal error: Object of class stdClass could not be converted to string
- variable value disappears in a second loop
- unknown issue in ‘header.php’ preventing theme from displaying fully
- Add meta tags to a custom header
- Ajax filter button display all posts
- Check If Post Was Published More Than 6 Months Ago Using get_the_date
- random display categories – change url
- Generate responsive post thumbnails of same size
- How to prevent a function from running based on host (ie web vs local)?
- Change out put of the_post_thumbnail in PHP
- Styling an “active” link outside of WordPress default menu
- WordPress permalink issue
- Any way to hide a blog posts text if it’s longer than let’s say 300 characters
- Delete images from media library when user deletes an image from ACF Gallery
- Array data not saving to specified sections. How to make seting independantly?
- How to get woocommerce orders with get_posts method in a shortcode
- Change category thumbnail size
- how to make wordpress user submit form once?
- Need to show 7 posts from actual date
- How to reload a php script, using AJAX and jQuery
- Make wp_editor required
- I need to edit a widget, with no dashboard access
- problem in using wpdb->prepare and a string placeholder
- Custom content using in_category
- Get the total Author Favorited posts
- Need help with PHP functions
- WordPress WPDB::insert 13th param is always blank (only if format)
- When using shortcode, content stops generating after the_content
- MySQL query in WordPress with AJAX
- How do you detect if a specific word is at the end of a the_title()
- WordPress styling recent post
- Combining fancybox with multiple thumbnail plugin
- How to display thumbnail if post is assigned one otherwise not
- How to check “From Email” via WordPress before an email is sent
- Add specific phrase after every product title including the discounted price? [closed]
- Remove Unused Menu Locations
- How do I change the Go To Categories link in the term_updated_messages
- How to pass javascript var to php var