سؤال

Post and page guids include the full absolute URL of my site (e.g. http://www.example.com/wordpress/?p=1). This causes a problem if the domain, or wordpress path changes, or if I'm viewing the site via its IP address rather its domain, etc.

Problem 1: there are some internal links on my site that are using the guid. I'm guessing this is wrong and I should rewrite the template code to remove references to the guid - correct?

Problem 2: images are inserted into a post using their absolute URL, rather than a relative one. This seems short-sighted, but I'm wondering if there's a reasonable reason for that. Is there a way to change that behaviour?

هل كانت مفيدة؟

المحلول

1) The GUID is exactly that -- a GUID. It's used to uniquely identify the post. If you need to link to a post, then use get_permalink( $post_ID ) ($post_ID is optional) (link: get_permalink).

2) Not without a plugin, no. There's talk of using an image shortcode for 3.1 though, or maybe 3.2.

In the meantime, you can try using an alpha version of my Regenerate Thumbnails plugin:

http://viper007bond.pastebin.com/XprbYtg2

It'll go through all of your posts and update all image tags.

Make sure you back up your database first though. The code is alpha and not guaranteed to work, although I have tested it quite a bit.

نصائح أخرى

Problem 1: Yes, you should not use the guid in the template code. See this recent thread from the wp-hackers mailing-list:

http://lists.automattic.com/pipermail/wp-hackers/2010-September/034559.html

Problem 2: This question is actually one of the most discussed. :)

http://lists.automattic.com/pipermail/wp-hackers/2010-September/034652.html

http://core.trac.wordpress.org/ticket/11394

1.) GUID's in WordPress primarily exist for RSS readers. They are supposed to be unique identifiers so RSS feeds don't republish the same content over and over again. They are not designed to be used within WordPress posts or pages. Even though they may look like permalinks, they aren't and should never be confused with them.

For this reason, the URL part of the GUID should never be changed. If you change domains the GUID shouldn't be updated. The feeds have gone out under the old domain, not the new one, so changing the URI in the database will just annoy your readers, who will see old content being churned out all over again.

2.) Images can be made root-relative by editing the path when you insert them. If you need to change old images, backup your database and grab the Search Regex plugin. Searching in content for scr should show all the images used in your content.

For best performance cross-browser its wise to set base href in your .htaccess file to your site root if you are using relative links.

The problem with Wordpress GUID is that they look the same as URL - so some smart-asses decided to use them for url - the guids should better be some random numbers or something similar...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى wordpress.stackexchange
scroll top