-
Add the PDF attachment ID as a custom field value, for example
attached_pdf_id
. -
Get the URL using
wp_get_attachment_url()
:
<?php
if ( is_user_logged_in() ) {
$pdf_link = wp_get_attachment_url( get_post_meta( get_the_ID(), 'attached_pdf_id', true ) );
if ( $pdf_link ) {
?><a href = "https://wordpress.stackexchange.com/questions/89809/<?php echo $pdf_link ?>" >Download</a><?php
} else {
?>Sorry, no link available. Please contact the webmaser.<?php
}
}
?>
Related Posts:
- Permalink / sub-template issue
- How to use relative links on my pages?
- How can I store page ID in a post instead of other selected permalink?
- How to get a page url by a page id?
- Why does WP not use relative links when linking pages?
- Menu Link Redirect Based on Username or User ID
- Social Media Links on homepage – within posts/post loop
- Change website URL without breaking links or images? WP 3.3
- Is it possible to list post attachments in a sub URL endpoint with a dedicated template?
- Redirect user if it’s not logged in
- How to get full content including template HTML
- WordPress not respecting template hierarchy (fetches index.php instead of single.php or page.php)
- I copied my site to another site but all links point to old site
- Link to blog index from template
- Change author slug and functionality
- Best way to add internal link in widget
- Confusion about how a URL is being parsed
- Automatically append ID to at the end of specific URLs
- why some permalinks adding characters/ruining links
- Avoid WordPress categorizing a permalink request as Not found 404 Page
- How to change old permalink?
- Migrated from Windows to Linux. Any bulk methods for fixing case sensitivity?
- How to eliminate permalink prefix in WordPress Multisite
- Get the url of a page template without using the page slug and ID
- All top-level pages are using index.php as template
- How to generate a list of all urls
- WordPress Not Using Template Files After Permalink Update
- Changing permalink name redirects to another template?
- Format HTTP links
- Edit permalink for certain pages
- cannot link a external url, present page url acting as parent url
- Can WP give a value a post ID?
- implement separate templates for 1 post type
- Moved site, Old links in pages still pointing to old host
- How to use page jumps to top of banner and page title?
- Access or edit custom generated permalinks with WP_Rewrite
- How to remove the link of an image on WP 4.2
- optional parameter in permalink structure
- Create custom links for excerpts with php dynamically
- How can I see a list of all pages my WordPress site has generated?
- How to make different urls for some tags pages
- A dash can replace a period in a link, how to fix it
- My WP homepage works, but the other pages don’t when accessing from out side of my network
- Can I link to content dynamically from a page to a new page?
- Propper way to set anchor and url param
- Find internal links to post
- rebuilding/ rewriting a url to make it SEO friendly
- Remove link function from oembed image or video
- Single.php not loading when permalink only contains date information
- Rewrite single template permalink?
- How to change dynamic link to relevant post
- Difference and usage of uri (e.g. get_directory_uri) and absolute path (e.g. get_directory)
- single.php being ignored, going straight to attachment.php
- Possible to hide parts of the slug from get_template_directory_uri and bloginfo(‘template_directory’)
- After changing permalink settings, everything works fine except for the two most recent posts
- Select page/template from the permalink url
- Latin character conversion
- Pretty links for PHP pages above WP /blog directory?
- Permalink structure as code in back-end?
- What is the issue with our links? It creates a loop
- Text in permalink
- Choose template depending on URL
- Image not Showing (Can see image in inspect element)
- PHP Button Custom link [closed]
- Make all internal links relative, or otherwise make a website accessible from multiple domains
- WordPress Version 6.6 facing “This block has encountered an error and cannot be previewed.” which edit text on page with link
- Unable to access a folder that does not belong to WordPress installation
- After post URL change also automatically change references in posts to that new URL?
- Page linking issue
- Include other parameters in permalinks for better management of browser history
- standard post with extra parameter brings permalink problem
- redirect old pages by .htaccess
- get_permalink returning first letter
- custom permlink .htaccess file 404 Not Found error
- Custom rewrites for pages and categories
- get_permalink to attachment not working
- Permalinks of New Pages and their Parents
- Leverage permalinks with AJAX
- Custom permalink to make a page respond properly
- Styles are not loading when changing permalink to %postname%?
- Appending a variable to RSS link url
- Routing ‘fake’ sub sub posts
- Performance and styles not working fine after changing permalink structure
- My wordpress site must be being affected by outside sources [duplicate]
- Hyperlinking images on posts to permalink
- URL to an image in a post is changing when permalink is set to custom. Can I avoid this?
- Why are all pages redirecting to homepage when using custom permalinks?
- How to avoid duplicate Url for the home page
- Create a permalink for a post’s attachments
- region selection
- Redirecting From An Old Permalink Structure
- Change the author posts link using custom user metadata
- Files placed in directory with wordpress 404
- Custom url for portfolio post type and for posts [duplicate]
- Are custom page templates being used to get this permalink structure
- wordpress home is gone
- get_posts displaying wrong permalink for “continue reading” link
- WordPress custom permalinks, pages are now 404
- Generate multiple tag query URLs
- WordPress home page showing 404 error