Support » Fixing WordPress » Link title to PDF or external URL

  • Resolved Andrew Tegenkamp


    I want to add some content without real content but instead just have a direct link to a sister site or a direct downloads of a PDF. Is there a way to do this so I can skip the extra step of “click here to view” in my post?

Viewing 9 replies - 1 through 9 (of 9 total)
  • equalmark


    Do you mean that you want to add a post, and when that post is clicked on you want it to download a PDF rather than actually linking to the post?

    Yes, that is what I am hoping to do. Any ideas?



    Put this in a page:
    <embed src="" width='770' height='490'</embed>

    after uploading the wanted file through media upload.

    but do not go to WYSIWYG because that will kill the code.

    Got this today from another topic and the idea was from Samboll (I believe, can’t find it back now)

    Not a bad idea. But there are a few drawbacks that make it not work for me.

    1. When you click on the post it still links to the post instead of leaving you on the page.

    2. In FF the default seems to be to load it outside the window in Adobe Reader so if you load a page that has this post it automatically loads that PDF by default.

    3. It doesn’t work for me in IE8. That may just be me though. I changed it to iframe and it works like FF above but gives me a download file warning.

    Ultimately I’m also looking for a solution that allows you to use an external URL. I could use iframes for that but would prefer a direct link in some cases.

    Well, I believe after looking at Custom Fields that this is the way to go. I found that using custom fields called “link” and “target” will work to post a link to any file or website with any target (or this code defaults to _blank). Here is how I modified index.php in the default theme. I need to modify the category and archive pages as well but this is the general idea on the blog homepage:

    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    					$post_id = get_the_ID();
    					$linkVal = get_post_meta($post_id, 'link', false);
    					$linkVal = $linkVal[0];
    					if ($linkVal) {
    						$targetVal = get_post_meta($post_id, 'target', false);
    						$targetVal = (!is_array($targetVal)) ? '_blank' : $targetVal[0];
    						?><h2><a href="<?php echo $linkVal; ?>" target="<?php echo $targetVal; ?>" rel="bookmark" title="Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2><?php
    					} else {
    					<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    					<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
    					<div class="entry">
    						<?php the_content('Read the rest of this entry &raquo;'); ?>
    				<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    				<?php } ?>


    Hi Andrew, I am afraid that coding is a bit over my head.
    It does work for me in FF. Check this link out:

    This is one of 14 child-pages from here:

    I don’t know about IE8 (will test later) Browsershots is too busy now.

    I needed my trick because the newest year list (2009) was only supplied in Acrobat and converting it to my old format is too much pain. Besides, with the old pre formatting I hit a character limit and had to put a workaround in my config file (but that’s another story).

    By the way, I was out for a long day and we are in different timezones, hence the delayed response.

    It looks like your solution works well in FF and IE for me. I was trying to get it to download the PDF rather than embed it like you have done so I will have to see if this will work just as well, as I think it looks rather nice how you have done it!

    Can I ask if your page at is automatically updated when you add a sub page like ?

    If so, may I ask how you went about that? My ultimate goal for this project is to make a quick news list out of a category that is automatically updated when you add an item to that category. I think it will look a lot like but I am hoping to have posts automatically added to the list as the users all add things.




    Yes Andrew, it does it automatically. I choosed this because I saw no method to do it in a menu (there are 15 children now and it will grow for a long time with one per year).
    The trick is sort of described here: and here

    In short:
    create an empty (mother) page.
    create a specific page-template for that empty mother page

     * @package WordPress
     * @subpackage Default_Theme
    Template Name: eindstandenarchief
    <?php get_header(); ?>
    <?php include('left_sidebar.php'); ?>
    <div id="container">
    <div class="entry">
    <h2>Hier vindt u de eindstanden van het ONK Enduro vanaf 1995:</h2>
    <?php wp_list_pages('sort_column=menu_order&child_of=698&title_li='); ?>
    <h4>In het <a target=_"blank" href="">KNMV archief</a> vindt u de complete uitslagenlijsten vanaf 2003</h4>
    <?php include('right_column.php') ;?>
    <?php include('right_sidebar.php') ;?>
    <?php get_footer(); ?>

    then you are set to go and create child-pages and the links will appear in the mother page. (My child-pages also use a specific wide template but that is not relevant).
    In the template copy exactly line 6,7 and 8 with the slashes and the (your own) template name (that is a sensitive set of lines with the proper spaces etc).


Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Link title to PDF or external URL’ is closed to new replies.