Support » Fixing WordPress » Upload file (like pdf) and display as a link

  • Resolved aledan


    Hi! I have a problem with file attachment. After I have uploaded a file (pdf) in a post I wanna display it as a link (when you click on it the browser ask for download or open it) in a place I have reserved for pdf attachment in the single.php page. So I don’t want use “Inset into post” function.

    Now, I can do this with image thanks to this function.

    How I can do for other file? (like pdf?)

    Thanks and sorry for my little english

Viewing 4 replies - 1 through 4 (of 4 total)
  • Just put a link that is that file’s URL in either the post content, the page content, or even the template.

    I believe most browsers will display the PDF and give you the option to save it.

    Thanks for the reply, but I need a more autometic way for do it 🙂

    So, after long reading and surfing, I wrote this function.

    <?php function postfile() {
    	if ( $files = get_children(array(
    		'post_parent' => get_the_ID(),
    		'post_type' => 'attachment',
    		'order' => 'ASC',
    		'orderby' => 'ID',
    		'post_mime_type' => 'application',)))
    		foreach( $files as $file ) {
    			$file_title = $file->post_title;
    			echo '<a href="'.$attachmenturl.'">'.$file_title.'</a>';
    	} else {
    		echo "Nessun allegato disponibile";

    thanks for the function! it’s very helpful! 😉



    I can’t seem to understand how to use this.

    What does the function do? As I am also looking for an automatic PDF downloadlink. An easy to use “place PDF, and the it shows as a PDF downloadable link on the post” function.

    I am not familier to the functions php codings in wordpress yet, but I am trying to learn.

    Anyone care to explain this function for me?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Upload file (like pdf) and display as a link’ is closed to new replies.