WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using a Page Links To plugin that allows me to link the post title to an external web page, rather than to the content of the post. And I link some of the post titles to external pages, and others – to pdf files, stored in the uploads folder of my site.

I want to add a little pdf icon to those post titles that are linked to pdf files. To be able to do so, I want to add .pdf class to those post titles whose links end with .pdf.

Here's how the corresponding part of the page source looks:

<article id="post-123" class="post-123 post type-post status-publish format-standard hentry category-news">
            <header class="entry-header">
                                <h1 class="entry-title">
            <a href="http://www.mysite.com/path/to/directory/pdfs/mypdffile.pdf" title="My WordPress Post Title" rel="bookmark">My WordPress Post Title</a>

    </header><!-- .entry-header -->

            <div class="entry-content">
                            </div><!-- .entry-content -->

    <footer class="entry-meta">
        <a href="http://www.mysite.com/path/to/directory/pdfs/mypdffile.pdf" title="1:19 pm" rel="bookmark"><time class="entry-date" datetime="2013-04-23T13:19:30+00:00">April 23, 2013</time></a> 
            </footer><!-- .entry-meta -->
</article><!-- #post -->

What would be the best way to do that in WordPress?

share|improve this question
How do you generate the post title markup? – toscho Apr 23 '13 at 13:28
I'm not sure if I understand the question. Off the top of my head, my answer would be: "automatically" – but something tells me that's not what you expected me to say, @toscho. Please take a look at the source code I pasted in the body of the question - maybe that answers it in some way? – Astoria Apr 23 '13 at 13:36
Yes, that’s a good step forwards. :) But we have to see the PHP code to suggest a solution. – toscho Apr 23 '13 at 13:37
Okay, @toscho – a php code for the Page Links To plugin – or php code for something else? – Astoria Apr 23 '13 at 13:39
The PHP code that generates the content of the <h1>. – toscho Apr 23 '13 at 14:39
up vote 2 down vote accepted

There is no need to add anything via WordPress, you can simple add the following rule to your CSS file:

a[href$='.pdf'] {}

This will target all links pointing to a URI ending in .pdf. This works in all modern browsers and from IE7 upwards.

share|improve this answer
Brilliant. Thank you very much, @Fränk! – Astoria Apr 23 '13 at 14:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.