Support » Plugins » filtering short permalinks

  • Resolved Cailean

    (@cailean)


    I want to do the following:

    permalink structure:
    /post/%post_id%/%postname%/

    this works fine and allows me to use either the full permalink or to drop the name and just use the id (IM, email, twitter, etc) – kind of a built-in tinyurl.

    Problem is I don’t want the short version indexed by the search engines (dupe content, etc.)

    Any ideas how I could add:
    <meta name="robots" content="noindex">
    to the header ONLY when the short version is used? (ie: when the post title is not in the URL)

Viewing 4 replies - 1 through 4 (of 4 total)
  • Cailean

    (@cailean)

    managed to cludge this together… (in the theme header)
    `
    if (ereg(‘^/post/[1-9]*/?$’, $_SERVER[‘REQUEST_URI’])) {
    echo “<meta name=\”robots\” content=\”noindex\” />”;

    Is there a better way?

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Doesn’t the short version do a 301 redirect to the long version anyway? It should be, with WordPress 2.3 and up.

    Kafkaesqui

    (@kafkaesqui)

    Doesn’t the short version do a 301 redirect to the long version anyway?

    You’d think so, but apparently not. WordPress seems perfectly happy accepting a partial url with just the ID.

    Cailean, here’s a more WP way to do this (and a tad more efficient for using strpos()):

    <?php global $post;
    if ( is_single() && (strpos($_SERVER['REQUEST_URI'], $post->post_name) === false) ) {
    	echo '<meta name="robots" content="noindex" />';
    } ?>
    Cailean

    (@cailean)

    Otto42: That would be ideal – but it doesn’t happen.

    Kafkaesqui: Thanks for that!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘filtering short permalinks’ is closed to new replies.