How to add a custom button
-
Hello,
In order to implement my board, I want to put a link a the top right of my forum main page which will redirect to [bbp-topics-index] like that :
I’m thinking using <span onclick=”window.location.href=’www.google.com’;”>text</span>
but I don’t know where to put it in my child theme.Can someone help me please ?
Thanks!
-
there is a hook in the content-archive-forum.php file you can use
bbp_template_before_forums_index
so
add_action ('bbp_template_before_forums_index' , 'rew' ) ; function rew () { //your code here eg echo 'hello' ; }
Hello Robin, once again your advice rocks!
Here is my result :
Function.php of my child theme :
add_action ('bbp_template_before_forums_index' , 'rew' ) ; function rew () { echo '<p><a href="new-posts/"><div class="newposts">Show new posts</div></a></p>' ; }
and my css :
.newposts { float: left; background-color:#DD9933; padding: 5px 6px; margin:-65px 5px 2em 0; } .newposts a { color:#f2f2f2 !important; border:none; border-radius:0; box-shadow: none; color:#ffffff; font-size:13px; } @media(max-width:580px) { .newposts { float: right; background-color:#DD9933; padding: 5px 6px; margin:-15px 0px 2em 0; } .newposts a { color:#f2f2f2 !important; border:none; border-radius:0; box-shadow: none; color:#ffffff; font-size:13px; } }
I had to make a custom CSS to get it responssive with mobile phones.
I still got a little issue which is that my buton dn’t appear when you’re not connect, I need to fix that!
Thank you for writing the final solution – it’s useful for everyone)
great – glad you are fixed !!
Thanks Robin but I don’t think this is the easiest way for me to make this button available for users and guests.
When [bbp-topic-index] is available for all (no restrictions in my board), I just need to put my button available for everyone.
I’ve tried this :
add_action ('bbp_template_before_forums_index' , 'rew' ) ; function rew () { if(!is_user_logged_in()) return; echo '<p><a href="new-posts/"><div class="newposts">Show new posts</div></a></p>' ; }
and
function rew () { if ( is_user_logged_in() ) { echo '<p><a href="new-posts/"><div class="newposts">Show new posts</div></a></p>' ; } else echo '<p><a href="new-posts/"><div class="newposts">Show new posts</div></a></p>' ; }
But doesnt works..
that button would show in all cases – at a guess I’d say you have caching software that might need resetting.
I don’t have anything like that.
I only got few plugins linked to bbpress (bbp Style pack, unread posts, etc..).
ok, just tested and my original code works fine on my test site.
it could be a theme or plugin issue
Themes
As a test switch to a default theme such as twentytwenty, and see if this fixes.
Plugins
If that doesn’t work, also deactivate all plugins apart from bbpress and see if this fixes. if it does, re-enable one at a time to see which is causing the error.
If you cannot do this to your site (say because it is live) then use the ‘troubleshooting’ features of this plugin to let you test without affecting other users
Then come back
The issue comes from my theme, maybe too much modifications.
I really don’t know how to solve this instead of using another method to create my button..
so if you go to this tab
dashboard>settings>bbp style pack>Not working ?
and look at no. 2 – are there any files listed in there?
It detect the folder “templates” in the theme. (orange color)
CSS part is green.
I’ve installed a fresh version of my original theme + created a new child theme.
If I modify the function.php of the original theme, all works well.
If I add my content to the function.php of my new child theme, nothing appears…I can’t get the new child theme working, like my current one.
Anyway, strange thing is that I can see the piece of code when I inspect the source with a browser :
<div class="bbp-breadcrumb"><p><a href="xxx" class="bbp-breadcrumb-home"><span class="bsp-home-icon"></span></a> <span class="bbp-breadcrumb-sep">›</span> <span class="bbp-breadcrumb-current">Forum</span></p></div> <p><a href="lasts-topics-posts/"><div class="newposts">Show new posts</div></a></p> <ul id="forums-list-0" class="bbp-forums">
It seems to be hidden by something..
ok, does my style pack list any files changed in your theme under section 2?
Sorry it’s in french :
that’s no problem, and yes it doesn’t look like the issue is in there.
so the original code works fully with logged in, but not at all with non logged in- yes?
That’s right! And when I check on the source code in a browser while non loggued, I can clearly see the code with the button.
ok, so
1. can you post the exact code you are now using
2. can you tell me where your are putting this code?I’ve just taken a look at your site
the issue is the css
.newposts { float: left; background-color: #DD9933; padding: 5px 6px; margin: -65px 5px 2em 0; }
if you take out the ‘margin: -65px 5px 2em 0;’ then the code is on screen, otherwise it is offscreen
Once again you are right..
So now I need to double my CSS for loggued and non loggued users.. Any idea ? 🙂
so what is that bit of code trying to do ?
you mean my trick with the margin on the CSS ?
yes
With CSS :
Without CSS :
I was trying to align it with the Mark all as read button…
not sure I can see from that what the difference is – can you onky take out the margin line, so the background etc. is still there
You can see it now, I put :
.newposts { float: left; background-color:#DD9933; padding: 5px 6px; margin:0px 5px 2em 0; } .newposts a { color:#f2f2f2 !important; border:none; border-radius:0; box-shadow: none; color:#ffffff; font-size:13px;
Guests view :
Loggued users :
- You must be logged in to reply to this topic.