Michalis Vranis
Michalis Vranis

Reputation: 37

Wordpress permalink without domain name

OK it might sound stange but I am facing a good challenge with wordpress. when echoing the_permalink(); and checking the portfolio pages, I am getting a link something like this:

http://www.domain.com/?portfolio=test 

(Where test is the portfolio name).

Is there any option to return the permalink trimmed to ?portfolio=test keeping out the domain url? While asking, I think I got the answer already (trim()) but I would like to hear your ideas too.

every answer will be much appreciated!

Upvotes: 1

Views: 3653

Answers (1)

Matt Gifford
Matt Gifford

Reputation: 1268

You can obtain the permalink of a post by doing something like so:

<?php 
    function my_permalink() {
        echo substr(get_permalink(), strlen(get_option('home')));
    }
?>

The get_option method replaces the deprecated get_settings method, and allows you to retrieve named option values from the database:

http://codex.wordpress.org/Function_Reference/get_option

The 'home' value passed in to the get_option method will return the site URL.

Upvotes: 4

Related Questions