Gravity Forms Plugin for WordPress

32 responses to “How to filter a WordPress theme’s ‘more link’ text”

  1. The Frosty @WPCult

    Totally simple! Love it!

  2. Aaron

    Between your and Ian’s wonderful code tutorials, I might actually finish (and release) a proper child theme for Thematic.

    Thanks Justin!

  3. Upper Fort Stewart | Daily Digest for July 3rd

    [...] Theme authors: No need for custom more link filter hooks. Use WP’s filter hook instead: http://justintadlock.com/?p=1737 [#] — 3:25am via [...]

  4. links for 2009-07-02 « Twan van Elk

    [...] How to filter a WordPress theme’s ‘more link’ text (tags: WordPress more link themes functions.php) [...]

  5. Replacing the “read more” link on your WordPress blog

    [...] goes to Justin Tadlock for this great recipe! If you enjoyed this article, please consider sharing it! [...]

  6. Webwinkel

    @ Justin, the script above, using the_content_more_link filter hook, just works for WP 2.8 ?

  7. David Zemens

    Thanks for the tip. Also remember that you can style your more-link text using the CSS class:

    .more-link {
    }
  8. Ed

    Justin, is it possible to have an image for this custom more link?
    And apply it to specific categories as well?

  9. David Zemens

    I don’t want to hijack any answer Justin might give, but you can have a background image attached to the .more-link CSS class and can easily apply a single image to the more link.

  10. David Zemens

    @Ed,
    As a followup, I used this PHP code to add a class to the container that the more link is in. By doing so you should be able to apply additional CSS markup to add a different background image based on the category ID number.

    cat_ID;	?>

    I think.

  11. David Zemens

    Sorry, the PHP code was stripped out of the post above. Let’s try it again:

    cat_ID;	? >
  12. Ed

    No problem at all David! :)

    So how would that alter the above code snippet Justin posted in his post as a whole?

    Like this?

    I don’t know exactly how to apply your suggestion to the code.

  13. Ed

    Ah crap, same thing happens to me now.

    Let me give it another shot:

  14. Ed

    Okay this is not going to work for me, I can’t post the code in a comment.

  15. David Zemens
    $category = get_the_category(); echo $category[0]->cat_ID;

    I placed this code (contained withing the appropriate PHP tags) inside the container tag that the more-link was contained within. By doing this a unique container class can be generated depending on the category of the post.

    For instance, in my case it generated as such:

    as the 33 is the category ID of the category assigned to the post.

    Then, I suppose, you could use CSS to customize this class and serve up a different image for the more-link depending on the class.

    Make sense?

  16. David Zemens

    @Ed

    http://www.1955design.com/_powerlink/

    At the example URl above, I have styled the “Read the full article” link just as I described above. The .more-link class can be styled as desired, and the PHP code that gets the current category can be used to specifically style a CSS container. The red bordered link is styled in such a way that only items in category 3 received the red border. In this same manner you could apply a background image to the link that would be different for each of your categories. I hope this helps.

  17. Ed

    Hi David,

    Hmm, I’m still not sure how I need to use that line in combination with Justin’s code?

    Should I just add it under the second line?

    I’ve got the snippet here: http://snipt.net/Edwin/custom-more-link

  18. David Zemens

    @Ed,
    That code needs to be hard coded into your index.php file, etc. so that it applies the unique class to the division that the more-link is located in. Make sense?

  19. Ed

    @David,

    So I could basically add that line (Within the appropriate php tags) after the the_content template tag?

  20. David Zemens

    Not really. It needs to be added to the CSS markup that controls the container that the more-link is located in. Are you familiar with CSS?

  21. Ed

    @David,

    Okay, now you’re confusing me. :)
    The code line you posted surely can’t be posted in a CSS stylesheet?

    $category = get_the_category(); echo $category[0]->cat_ID;

    @Justin,

    Thanks for posting the code for the background image, I’ll check it out.

  22. Theme Playground | Community Link Roundup: Everything’s for sale

    [...] How To Filter The Read More Link [...]

  23. Jauhari

    My Question is..

    add_filter( 'the_content_more_link', 'my_more_link', 10, 2 );

    What for the 10 and 2 number above?

  24. Shibi Kannan

    Very nice discussion going on here, I would like to see more creative uses for the custom more link – any ideas !

  25. Keith Purkiss (Alex Jeffreys Student)

    Hi Justin,

    I’m finding a lot of useful stuff here.

    My homepage was getting a bit full so I’ve just edited a few posts and put in the
    tag to tidy it up a bit. I know there’s plugins that do something similar but this is so simple and you can choose where to put the tag to intrigue people – a bit like having a headline that makes them want to read more.
    Now I have a whole compact list a partial posts and I think it will get me more readers.

    Haven’t got as far as the advanced stuff yet ;)

  26. Simon Wilby

    I am using this one but not able to edit its style, like I want it to display in bold and underline.

    Can I change that on the stylesheet or in the functions.php itself.

  27. David Zemens

    @Simon;

    You should be able to add this class to your style.css file and style it accordingly:
    .more-link {
    }

  28. kaos murah

    My homepage was getting a bit full …yeah. but no problem

  29. Tiago

    Perfect! Just what I was looking for. Was able to hook it up on Thematic without any issues. Out of curiosity: what are the 10 and 2 numbers refering to?
    Thanks!

  30. neel

    Nice trick. i want to ask you can we apply filters in sidebar widgets. I want to change all links in sidebar and want to add affiliate id in front of all the links. can i do this using the filter . please let me know

  31. Jaxov

Leave a Reply

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution.

Please use your real name or a pseudonym (e.g., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.

Recommended Purchases

Gravity Forms Plugin for WordPress 'Digging Into WordPress' book for WordPress users

WordPress-o-Sphere

  • WordPress 2.8 – "Baker"
    WordPress 2.8 adds hundreds of bug fixes, adds cool functions for themes, boasts a new widget API, and makes custom taxonomies easy for end users.
  • WeRockWP
    WeRockWP recognizes and showcases the individuals who contribute much to the WordPress community. These individuals are called WordPress Rockstars.
  • wpazo
    The all-signal, no-noise, source for the best WordPress stuff.
  • BuddyPress 1.0 has arrived
    The long-awaited BuddyPress (a set of plugins that turns a WordPress MU install into a social network) has been officially released.
  • BuddyPress for WordPress (not MU) coming
    It looks like BuddyPress will also be released for normal WordPress installs (not just WPMU).