Skip to:
Content
Pages
Categories
Search
Top
Bottom

Small change to BuddyPress Default 1.2.3 theme

  • @pubdirltd

    Member

    How do I alter the default theme so that when I click on an RSS feed link it opens in a new window? I would prefer to keep my users on my site and provide them something interesting to read, not just send them somewhere else. I guess its somewhere in wp-contentpluginsbuddypressbp-themesbp-defaultfunctions.php – but where?

Viewing 7 replies - 1 through 7 (of 7 total)
  • @hnla

    Participant

    tbh it’s considered a bad thing for developers to do, the opening of new windows is a browser issue and as such it’s considered impolite to force your wishes on the end user. It is my decision as to how I deal with links not yours, if you try and disrupt my browsing habits I’m annoyed; regardless I override anything you might try and do so it’s largely wasted effort your new window becomes a new tab for me.

    This action is also a behaviour and as such the use of attributes is rightly deprecated, but they can be added via scripting. You could give the following code a try it would need to be added to a functions.php file in a child theme.


    function rss_new_win() {
    echo <<<SCRIPT

    <!--
    function bindNewWin() {
    jQuery("li.feed > a").attr({target:"_blank", rel:"ext"});
    return false;
    }
    jQuery(document).ready(function(){
    bindNewWin();
    });
    //-->

    SCRIPT;
    }
    add_action('wp_head', 'rss_new_win');

    I can’t vouch for how well this works, it’s tested and works ok but whether it breaks any WP/BP script inclusion rules I’m not familiar with i couldn’t say so it should be used cautiously ; also take note that it adds an attribute to all anchors that have a li parent of class ‘feed’ if that condition is not true then it would fail (the main feed on the activity steam is marked up in this fashion if others exist that are contary then they would need to be added in some manner to this code.

    IGNORE THE CODE POSTED HERE IT DOESN’T DISPLAY CORRECTLY grab from this pastebin link if you want to give it a go:
    http://pastebin.com/keBUmVxX

    @pubdirltd

    Member

    @hnla — This looks very interesting, I appreciate the detailed reply and I will certainly try out the pastebin example. There are a couple of points though. Did you pick up on the fact that this new page opening function was only to relate to pages being opened from an RSS feed? And, who exactly is this person or persons unnamed who consider it impolite that the website owner, who has had the expense and invested the time and effort to create the site, should not decide how it should function? I agree with you that it is your perfect right to handle a link in whichever way you want, to defeat what I set up, should you so choose. Nevertheless, I would be quite happy that my effort to open a new window turns into a new tab in your browser – job done, as far as I am concerned.

    @hnla

    Participant

    Did you pick up on the fact that this new page opening function was only to relate to pages being opened from an RSS feed?
    Absolutely! Note the reference to the li.feed above. The RSS item that I looked at was set with this token what the script does is look for all instances of this element with a class of ‘feed’ and adds a new ‘target’ attribute to the anchor. As I said though this is good to go where that condition holds true, if elsewhere there are feed links that decide to change that parent li token to ‘rss’ or not place the link in a list construct, but things can be amended. The core of the script is something I use all the time when I would rather ensure that the main page is not navigated away from.

    Opening new windows is generally considered to be something that should be done sparingly and only with good reason while understanding the implications thereof. It must be remembered that the general user is simply extremely unfamiliar with how something like a browser works, yes I trap new windows to tabs but if a inexperienced user is allowing new windows to open then what can happen is the classic confusion often referred to as ‘breaking the back button’ A new window opens as an overlay on top of and masking the original and this happens at lightning speed that many miss the event; this new window has no ‘history’ thus the back button has no function and that can massively confuse inexperienced users who can’t work out why it has ‘stopped’ working.

    It’s not a case that one can’t do this but that we need to be aware of how we are now interacting with what is regarded as user choice and that user choice is not something that authors are meant to try and control in any significant way.

    N.B I have adjusted the script posted to change the rel=”ext” to rel=”feed” as this is a more appropriate value in this instance.

    @pubdirltd

    Member

    @hnla – put me out of my misery. I’ve spent an hour or more trying to get this to work with the default theme. Where does it go?

    @hnla

    Participant

    Generally it would be placed in a functions.php file that lives in a child theme – are you running a child theme? if not I suppose it can be run in bp-custom.php file that lives in the plugin folder but haven’t tested whether that does work. You can place it in the default themes functions.php file but the problem there is that when you upgrade BP you will lose any mods made to this file and any others in the default theme which is why it’s best to run a child theme if planning on making a few mods.

    @pubdirltd

    Member

    I am afraid I had to give up in the end. I tried it in all three and it didn’t open any of the syndicated RSS articles in a new window. I am sure its down to my incompetence but that’s a product or heredity, environment and evolution, so it won’t be changed quickly and I have to get the site up and running, so I will leave it out for the time being. Many thanks for your help.

    @hnla

    Participant

    You would need to explain exactly what you tried as it should work, as long as the anchor has a parent named .feed? or was it.rss that is one possible issue and the script element check would need to be smarter or not so rigid.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Small change to BuddyPress Default 1.2.3 theme’ is closed to new replies.
Skip to toolbar