WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Not printing permalink in category and front (4 posts)

  1. kjellkk
    Member
    Posted 6 years ago #

    Hi there,

    I've tried searching for a while now to no avail so I'll pose my question and hope to be directed to the right answer if it already exists.

    Permalinks are working smooth as.

    I'm wanting to show the permalink on my printerfriendly pages (by CSS) as well as have a link to the Google translation service.

    To do this I'm using the_permalink()

    It works fine on any posts or pages, but for the front, category pages, or tags pages it will just show the permalink for the most recent post or page.

    I thought for a while that I had messed up the theme/template, not closing a loop or something, but tried with another and same problem. I'm still open to the possibility that some plugin might have messed this up, but good to hear from others before I check them all.

    The site in development is at http://v2.clusterprocess.org - I'll go out of development shortly so will make a workaround (not show permalinks on the mentioned pages) if I don't find a solution.

    Thanks,

  2. Adam Brown
    Member
    Posted 6 years ago #

    I looked at a print previous of your main page. From where the permalink shows up, I would guess it's not in a loop at all, right? It needs to be used within the loop to behave as expected.

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Right, the_permalink() is a Loop-only function. There are other functions for getting different types of URLs.

    If you just want the current url, there's no built in function to do that. But this function will do the trick, I think:

    function get_current_url() {
    	return (( isset($_SERVER['HTTPS'] ) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    	}
  4. kjellkk
    Member
    Posted 6 years ago #

    woops - you are right, not in loop. I guess I really should sit down and read more of the documentation.

    Anyway, thanks very much for that function Otto, serves my purpose very well.

Topic Closed

This topic has been closed to new replies.

About this Topic