Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Permalink without domain WordPress

  • SOLVED

Hello,

In Wordpress I need to have all my permalink without domain. I mean all links (navigation, images ...) but not external links.

I add these lines to functions.php without success :
http://wordpress.stackexchange.com/questions/32728/get-page-permalink-without-wpurl

function get_relative_permalink( $url ) {
return str_replace( home_url(), "", $url );
}

Answers (1)

2016-03-29

Rempty answers:

Try with this

add_filter('the_permalink','get_relative_permalink')

function get_relative_permalink( $url ) {
return str_replace( home_url(), "", $url );
}

why you need permalinks without domain?


guillaume guillaume comments:

Thanks Rempty for your answer.
I need this because the website will be reachable from two different url.

So I try your code in functions.php :

add_filter('the_permalink','get_relative_permalink')
function get_relative_permalink( $url ) {
return str_replace( home_url(), "", $url );
}

But all content has now disapear.


Rempty comments:

Sorry forgot a ";" please try again.

add_filter('the_permalink','get_relative_permalink');
function get_relative_permalink( $url ) {
return str_replace( home_url(), "", $url );
}


But if you will visit the page for 2 diferent urls, you will need the images, css , etc in the 2 different urls


Rempty comments:

Maybe a better solution is add

define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);


To your wp-config.php


guillaume guillaume comments:

Okay, content is back. I empty my cache browser to be sure.
Now, if I have a look at the "source" of one page I still have the domain in the url, for example :

http://mydomain.com/wordpress/portfolio/contact/

I wish it becomes :

/wordpress/portfolio/contact/


guillaume guillaume comments:

<blockquote>But if you will visit the page for 2 diferent urls, you will need the images, css , etc in the 2 different urls</blockquote>

Yes, all content (images ...) and css will be on two different server.


guillaume guillaume comments:

To have it clear, the goal is to have this :

<a href="http://mydomain.com/wordpress/portfolio/contact/">Contact</a>

Translated into that :

<a href="/wordpress/portfolio/contact/">Contact</a>


Rempty comments:

If not work the filter, maybe a better solutions is this
https://wordpress.org/support/topic/multiple-domains-one-site


define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);


Automatically will get the current domain url


guillaume guillaume comments:


define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);


Should I replace with domains, like this :


define('www.domain1.com', 'http://' . $_SERVER['HTTP_HOST']);
define('www.domain2.com', 'http://' . $_SERVER['HTTP_HOST']);


What to do with "HTTP_HOST" ?
Thanks


Rempty comments:

No just add the code without any modifications in your wp-config.php


guillaume guillaume comments:

The code allow to have two domains ?
No need to configure with my settings ?

I just need to paste this into wp-config.php


define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);

define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);


guillaume guillaume comments:

One last thing about your previous code :

add_filter('the_permalink','get_relative_permalink');

function get_relative_permalink( $url ) {

return str_replace( home_url(), "", $url );

}


I add this code to functions.php, shall I paste it to wp-config.php ?


Rempty comments:

Delete completly the code you added to your functions, you don't need the code anymore

Just paste this code to your wp-config.php


define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);


What do this code?
Automatically will detect your domain and set to the wordpress config.
$_SERVER['HTTP_HOST'] = www.mydomain.com


guillaume guillaume comments:

Perfect, thanks for the help.


guillaume guillaume comments:

Ooops,

The code has been added to wp-config.php
The result is not good, I lost all styles and content pages + admin panel access.


guillaume guillaume comments:

Rempty, do you have an idea why ?


guillaume guillaume comments:

Too bad you let me down on this ... a bit disappointed.


guillaume guillaume comments:

Okay, thanks Rempty for the follow up by email.