[wp-hackers] category URL's and SEO ranking
wordpress at zed1.com
Sun Jun 17 18:36:52 UTC 2012
On 17 June 2012 14:18, Haluk Karamete <halukkaramete at gmail.com> wrote:
> Thank you for the code. I have only a handful of cats, ( 20 so to speak ).
> And not all of them needs this kind o shortening. For example, a URL like
> , though longer, is better than
> Ofcourse, what's better or not is debatable but the point is for some
> cats, the site owner decides to go with the full url and in some the
> shorter one.
It actually sounds like some of your categories should be a different
> Having said that, would then the following adjustment to your code be
> OK to go with;
> add_filter( "term_link", 'my_term_link', 10, 3 );
> function my_term_link( $termlink, $term, $taxonomy)
> // check this is a category link, and we are using permalinks
> if ( ( 'category' == $taxonomy ) && ( false === strpos( $termlink,
> '?' ) ) )
> global $wp_rewrite;
> $termlink = $wp_rewrite->get_extra_permastruct( $taxonomy );
> $termlink = str_replace( "%$taxonomy%", $term->slug, $termlink
> $termlink = home_url( user_trailingslashit( $termlink,
> 'category' ) );
> $taxonomy_term = $taxonomy . "_" . $term;
You can't do this, the term is an object that is passed. And neither is a
number. The taxonomy is a string.
And my code only operates when the taxonomy is 'category' so you wouldn't
need to test for it again.
If you are thinking of numbers for these things you are thinking wrong: the
numbers are incidental and really only relevant to the database. Yes,
WordPress code uses ID's of various objects, but that is only because they
are convenient keys into the database record.
> case "3_10": //alternatively, I can go here
> "category_video" too right? Assuming the filter is called like that?
> //overwrite the WP computed URL alone when
> taxonomy ID is 3 and term id is 10
> $termlink = "/category/video";
Not sure why you haven't used the call to home_url() and backslashit()
> //leave WP computed URL alone
> return $termlink;
> Also, I could not understand the part " ( false === strpos( $termlink,
> '?' ) ) ) "
> When you check for the query string existence, what do you make of
> that? Does your original code uses the full URL ( that is
> /category/multimedia/video as opposed to /category/video ) when the
> URL happens to have a QS attached to it? Did I get this part wrong?
The code I wrote is checking whether pretty permalinks are turned on, if
they are not, the url will include a query string, and therefore the
manipulation does not need to be done.
More information about the wp-hackers