Forums

Change link text from wp_list_pages, instead of using page titles (22 posts)

  1. theMaab
    Member
    Posted 3 years ago #

    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.

  2. Technokinetics
    Member
    Posted 3 years ago #

    As it happens, I've just coded this, and was wondering where I could find someone to help test it. Are you game?

  3. theMaab
    Member
    Posted 3 years ago #

    Sure Thing!!!

    I was thinking I was going to have to make static links in the template to accomplish this. This will be a much better alternative, Thanks!

    I'll let you know what I find.

  4. theMaab
    Member
    Posted 3 years ago #

    Okay, got the plugin installed and activated, but right away I got this error in my menu bar where the page links would appear:

    Warning: preg_replace() [function.preg-replace]: Unknown modifier 'O' in /home/bbash/public_html/wp-content/plugins/alt-link-text/alt-link-text.php on line 108

    Possibly cause I have an ampersand (&) in my page title?

  5. iridiax
    Member
    Posted 3 years ago #

    theMaab: LOL, how many times did you click the Post button? I see 5 identical replies. ;-)

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

    To do this (and add custom link titles), I just create a link myself like this:

    <a href="<?php bloginfo('url'); ?>/about-us/" title="Info about my website">About My Really Cool Website</a>

  6. theMaab
    Member
    Posted 3 years ago #

    Yeah, I dont know what happen there, :( Sorry about that everyone.

    iridiax: That's not exactly what I want to do. I would like to have longer page titles for my Pages. The problem is when you create the links for the pages, in my horizontal nav bar (which is 900px wide) the long page titles are too long. So, I would like to have an alternate string to use for the page links created by wp_list_pages.

    Technokinetics : Thanks a mill for the plugin. But it doesn't seem I can get it to work correctly.

    I found it was not the ampersand (&) causing the problem but a forward-slash (/) I had one in my page title and it did not like that and is what generated the error I posted above. So, it would be nice to have it handle the forward-slash (/), really most all characters would be good.

    However, there still seems to be something wrong/not working. I removed the forward-slash from my page title, and that got rid of the error. But, my menu bar still shows the long page title.

    I did see and filled in the 'Alternative Link Text' box with my short text, but it's not showing that.

    BTW this is exactly what I was looking for and you did a great job on the plugin. Good placement of the Alternative Link Text box, fits in nicely.

  7. theMaab
    Member
    Posted 3 years ago #

    Technokinetics : after reading iridiax post again, I thought that would be a cool thing to have in this is a custom link title too. Good thinking

  8. Technokinetics
    Member
    Posted 3 years ago #

    Thanks for the help with this.

    I can replicate the problem with special characters, and will see what I can do about that.

    Other than that, the plugin works fine on the two sites that I've used for testing. Could you point me to yours so that I can see what's still going wrong? Thanks.

    Oh yes, adding a custom title attribute option in a later version will be straightforward enough; will add that to the to-do list.

  9. Technokinetics
    Member
    Posted 3 years ago #

    Okay, the version currently available for download (v0.2) can cope with titles including & or /.

  10. Technokinetics
    Member
    Posted 3 years ago #

    Alternative title attribute support added in v0.3.

    N.B. If you just overwrite the old alt-title-text.php file with the new then the alternative title attributes won't work. The database column used to store alternative title attributes is created when the plugin is activated, so you'll need to deactivate and reactivate the plugin.

  11. theMaab
    Member
    Posted 3 years ago #

    Hi Technokinetcs,

    I've got the new version of the plugin, got it installed and deactivated and re-activated.

    I thought it was still not working, but found it is.
    For some reason the page I kept trying, it didn't like.

    I've now tried other pages and everything works for it beautifully. It takes the long page title, but uses the shorter version for the link, and the link title works great too!

    I'm not sure why that one page doesn't work. I bet if i delete that page and recreate it, it will work fine, which is what I'll do.

    The site hasn't 'launched' yet, so it wont' cause a problem. Using seo friendly urls anyways, so can make the new page match the old.

    Thanks for the great plugin! Sorry to have caused more work with my weird problem.

    Please email me at 'james' 'mm' at 'gmail' and I'll send a link to you for the site.

    Thanks again!

  12. theMaab
    Member
    Posted 3 years ago #

    Well, it seems the new plugin is not working.

    I ran into some other pages where it kept using the page title.
    And then I've found it also looses the values for the Link Text and Title Text. Seems at random, at least I can't tell what causes it to loose them.

    On a separate note I'd still like you to contact me to talk about something else I've been wanting to do recently.

    Thanks

  13. Technokinetics
    Member
    Posted 3 years ago #

    Hi James,

    I can't recreate the problems you're seeing, but the point of testing is to pick up on issues that arise with different site setups; this is all very useful.

    I'll be in touch so that I can find out what the specifics are, and fix any bugs before I make this more widely available.

    Will post back here when the plugin is ready for general release to wrap up this thread.

    Tim

  14. nibb
    Member
    Posted 3 years ago #

    Hi,
    I've recently tried the plugin with WP 2.6.1 and WPMU 2.6. In WPMU it doesn't supply anything to the editor interface, and in WP it does actually provide the wee box for the alternate link, but then doesn't use whatever you put in there.

    Any ideas?

    Would be great to see this one work well, I used to use the stub instead of the title to form navigation buttons, rewriting myself a copy of wp_list_pages. This has stopped working, and its not really a solution if you intend to keep upgrading WP.

    thanks for the effort

  15. Technokinetics
    Member
    Posted 3 years ago #

    Hi Nibb,

    Please drop me an email (tim at technokinetics.com) with a link to your site (and preferably an admin login) and I'll take a look.

    The plugin works absolutely fine on some sites (including James's now). Hopefully we can work out what's different about your WP installation that I haven't taken account of, and get this resolved so that more people can use the plugin.

    Thanks,

    Tim

  16. Technokinetics
    Member
    Posted 3 years ago #

    The one known issue with this plugin (where a title to be replaced contains a special character such as "&" or "/" no replacement of any titles takes place) has been resolved in v0.4, which is now available for download.

    If anyone is having problems that aren't fixed by switching to v0.4, then I'd really appreciate an email (to tim @ technokinetics .com) explaining what isn't working.

    If I don't hear from anyone in the next few days, then I'll make a v1.0 available in the WordPress.org Plugin Directory. Thanks to all who have helped with this.

    Tim

  17. doodlebee
    Member
    Posted 3 years ago #

    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.

  18. Technokinetics
    Member
    Posted 3 years ago #

    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

  19. doodlebee
    Member
    Posted 3 years ago #

    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.

  20. Technokinetics
    Member
    Posted 3 years ago #

    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. :)

  21. abelq
    Member
    Posted 3 years ago #

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

  22. Technokinetics
    Member
    Posted 3 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic