• How could I allow any links contained in my posts, as well as the links listed in my upper-right to always open in a new window (and still keep all other links in my blog opening pages in the same window?)

Viewing 7 replies - 1 through 7 (of 7 total)
  • Simple, but *invalid* as XHTML:

    <a href="site.com/etc" target="_blank">link text</a>

    Less simple, won’t work if Javascript is off, but valid as XHTML:

    <a href="site.com/etc" onclick="window.open(this.href,'_blank');return false;">link text</a>

    Even less simple (but cool!) Javascript method:

    http://www.sitepoint.com/article/standards-compliant-world

    And finally, to add one of these automatically, look at my Add Link Attribute plugin:

    http://guff.szub.net/add-link-attribute

    Thread Starter bi11i

    (@bi11i)

    wow, thanks!

    well, so after posting and screwing around with wordpress a little more, i noticed there’s a setting for allowing the links (at least the links via the menu bar) to open in a new window.

    is there a simple php or template that i could edit that would tell wordpress to open all of my existing posted links to open in a new window? i know the code to use – just don’t know where exactly.

    thanks!

    Where is the setting for allowing the links to open in a new window ?

    When editing individual links in the Links Manager look for the “Target” setting.

    Kafkaesqui, I downloaded your plugin, but to be honest, I’m having some trouble using it. All I want to do with it is add an attribute to links within posts (target=blank, obviously). Can you make it easy (er) for me?

    kjda: You could always just add them in each post…

    The add_link_attr() function “wraps” around any WordPress functions/tags you want it to perform on, so for post content, you replace

    <?php the_content(); ?>

    in your templates with

    <?php add_link_attr('content', '', 'target="blank"'); ?>

    If you use the ‘more_link_text’ parameter for the_content(), then do something like:

    <?php add_link_attr('content', 'Continue reading', 'target="blank"'); ?>

    However, note that Add Link Attribute has no way of ignoring the more link tag when it’s used, so it too would receive your attribute.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘links to open in new window?’ is closed to new replies.