WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] filtering short permalinks (5 posts)

  1. Cailean
    Member
    Posted 6 years ago #

    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)

  2. Cailean
    Member
    Posted 6 years ago #

    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?

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

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

  4. Kafkaesqui

    Posted 6 years ago #

    "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" />';
    } ?>
  5. Cailean
    Member
    Posted 6 years ago #

    Otto42: That would be ideal - but it doesn't happen.

    Kafkaesqui: Thanks for that!

Topic Closed

This topic has been closed to new replies.

About this Topic