Forums

How to make recent posts links open in new window using the widget? (20 posts)

  1. lollacorn
    Member
    Posted 1 year ago #

    Hi,

    I am using the Recent Posts widget in the sidebar of my wordpress blog.

    However, I want any recent post links that are clicked to open in a NEW window as opposed to the same one.

    Can anyone please tell me how I can do this?

    Thanks :)

  2. elfin
    Moderator
    Posted 1 year ago #

    I'd advise against it, but you'd need to add target="_blank" to the links, you may need a custom widget to accomplish this.

  3. ljmyers
    Member
    Posted 1 year ago #

    Never a good idea for your site's links to open in new windows . . . this usually annoys people and they may not revisit your site.

  4. lollacorn
    Member
    Posted 1 year ago #

    Hi,

    Do you know of any custom widgets that could add this attribute to the links?

  5. elfin
    Moderator
    Posted 1 year ago #

    no sorry I don't.

  6. lollacorn
    Member
    Posted 1 year ago #

    Does anyone know if the widgets.php file can be edited (or another file) to make this possible?

  7. FishDogFish
    Member
    Posted 1 year ago #

    You can add <base target="_blank" /> to your header.php and your links will open in a new window.

  8. lollacorn
    Member
    Posted 1 year ago #

    Hi,

    Thanks for the reply. Where in the headers.php do i add this to make my recent posts open in a new window?

  9. FishDogFish
    Member
    Posted 1 year ago #

    At the very top like this.

    <!-- header START -->

    <base target="_blank" />

  10. lollacorn
    Member
    Posted 1 year ago #

    Thank you very much!

    But is there any JUST to make recent posts from the recent posts widget to open in a new windows, and not ALL the links on my site?

  11. FishDogFish
    Member
    Posted 1 year ago #

    What code are you using to display the "Recent Posts"?

  12. lollacorn
    Member
    Posted 1 year ago #

    I'm using the standard Recent Posts Widget from WordPress (found in the Widgets submenu under the Appearance menu in the Control Panel).

  13. FishDogFish
    Member
    Posted 1 year ago #

    I don't have that widget, so I have no idea how to modify it.

  14. lollacorn
    Member
    Posted 1 year ago #

    If you click on the Widgets Submenu under the Appearance Tab in the WP Admin menu, it's just one of the standard widgets called Recent Posts (The most recent posts on your site).

    It's after Recent Commetns and before RSS in the list of Available Widgets.

  15. FishDogFish
    Member
    Posted 1 year ago #

    You might try finding the code that displays the links, and wrap an
    <a target="_blank" </a> around it.

  16. FishDogFish
    Member
    Posted 1 year ago #

    O.K. I figured it out.

    Find the code in the sidebar that displays the links, it's should be in an h3 element. Something like this.

    <h3 ><?php echo $posts_widget_title; ?></h3>

    Add <base target="_blank"> Between the h3 and the php, like this...

    <h3 ><base target="_blank"><?php echo $posts_widget_title; ?></h3>

    That should do it.

  17. FishDogFish
    Member
    Posted 1 year ago #

    You'll have to put an empty <h3><base target="_self"></h3> so all the links in the sidebar won't open in new window.

    It won't work with the widget installed because you can't edit the widget, but you can do it in the sidebar with php.

    It doesn't seem to work in IE either, but that could be due to browser settings.

  18. lollacorn
    Member
    Posted 1 year ago #

    Hi,

    I'll have a fiddle with that code if I go for the sidebar option as opposed to the widget.

    Thank you very much for all your help! :)

  19. FishDogFish
    Member
    Posted 1 year ago #

    There is probably a way to edit the widget using your FTP client, but you'll have to figure out where it's stored on your server.

    Personally, I think widgets should include a map to their locations so you can edit them if necessary. Or there should be a widget editor in WP.

  20. Blizzie
    Member
    Posted 8 months ago #

    Hello! What if I would like to open recent post link to a new window with different template/css format. How can I do it?

Topic Closed

This topic has been closed to new replies.

About this Topic