• Hi All,

    I’m trying to figure out how I can change the link text that comes from wp_list_pages template function.

    Currently my page names are short so that I can fit them horizontal in my menu bar. For example, the About Us link.

    And of course the page title is ‘About Us’. However, I’d like the actual page title to be something longer in length, like
    ‘About My Really Cool Website’.

    But, this long text is too long for my horizontal menu bar. How could I change my page’s text for links (generated by wp_list_pages/or alternative)? I’ve searched for a plugin but was unable to find one.

Viewing 6 replies - 16 through 21 (of 21 total)
  • Wow – I usually get around this with CSS. Usually, the title of the post (placed in the “title” section when you write the Page) is surrounded by h2 tags. If I want the link to say one thing, that the page title to say something else, I’ll name the post title what I want the link to show up as. Within the body of the text, the first thing I put in is <h2 class="showme">Real title of Page</h2> and then continue on with the rest of the content.

    then in the stylesheet:

    div.post h2 {
    display:none;
    }

    div.post h2.showme {
    display:block;
    /* insert other formatting here */
    }

    Voila – the link says what’s in the actual title, but the page shows the secondary one I stuck in. Done.

    Thanks for the suggestion, Doodlebee.

    One of my aims with Alt-Link-Text is to let users set up short versions of their titles without having to either edit their theme files or switch to code view in the dashboard. The plugin doesn’t require users to add any HTML or CSS, which is always a good thing.

    The plugin can also be used to modify a single navigation link; you don’t have to type in two versions of the title for every page as with your method.

    The main concern I have with your approach, though, is that your WP database no longer has the expected structure. The post_title field no longer contains the post title (instead it contains the anchor text), and the post_content field no longer contains only the post content. As someone who believes in accurately labelling data so that it can easily be used in a variety of ways, this makes me uneasy!

    It’s difficult to predict exactly what mislabelling the data might do, but here are a couple of knock-on effects:

    – Fetching the page title using the_content() rather than the_title() means that any plugin that hooks into the_title() (e.g. to provide a thumbnail image next to it, to truncate it, etc.) is unlikely to work, and any plugin that hooks into the_content() (e.g. to link specified words, etc.) will affect your title too.

    – The WordPress developers, in their great wisdom, have decided to apply different filters to page titles and page content. Your title is now being run through the other set of filters. (Whether this matters or not, I honestly don’t know, but it makes sense not to mess with these things without good reason.)

    – If you did this with posts, I’d expect an RSS feed to show both your link text as the title, and your title as part of the content.

    – If you ever want to insert something between your title and your content (e.g. author info, tags, etc.) this will be tricky, because with your method there’s no such place.

    Obviously your method is working well for you at the moment, which is great, but I hope that this at least goes some way to explaining why I think the plugin is worthwhile.

    Tim

    Oh, I think the plugin sounds cool. And I only do this for…smaller sites where the client has actually requested something like this (and the rest of the stuff you mentioned is definitely a good point – the RSS feed is one I’ve brought up with clients, actually) but they don’t see it as a big issue. I wouldn’t call it “mislabeling” though – the idea when this method is used is to *definitely* keep the “title” the same as the title – it’s just usually a more extended version of what the link will be.

    Mine is simply a workaround, that’s all. But if there’s a plugin for all this that makes it even easier – that rocks ?? I was just sharing what I do on occasion, not trying to discount your work.

    I’ve used workarounds in the past too. I’ve seen at least four different ways of doing this, but they all have their drawbacks.

    > I was just sharing what I do on occasion, not trying to discount your work.

    Don’t worry; no offence taken. I just felt the need to explain. ??

    I’m also looking for a way to easily change the label of pages that wp_list_pages generates and found this one… https://www.stuffbysarah.net/blog/2008/09/26/new-wordpress-plugin-page-menu-editor/ . I’m going to try it out.

    Just a quick update: As of v1.0, Alt Link Text adds a checkbox that lets you easily exclude Pages from your navigation menus. Any other feature requests, please let me know: tim @ technokinetics .com.

    Thanks,

    Tim

Viewing 6 replies - 16 through 21 (of 21 total)
  • The topic ‘Change link text from wp_list_pages, instead of using page titles’ is closed to new replies.