Shortcode Topic – Add Reply Form
-
Hi guys, I’m using the
[bbp-single-topic id=$topic_id]
shortcode to include a topic on my post. Would it be possible to have the reply form above the topic? How would I modify the template to remove the displayed breadcrumb as well?
-
ok the template you are after is
wp-content/bbpress/templates/default/bbpress/content-single-topic.php
this will alter it wherever this template is used.
make a copy of this template and put it in a directory called bbpress in the root of your theme, so you end up with
wp-content/themes/%your-theme-name%/bbpress/content-single-topic.php
where %your-theme-name% is the name of your theme
Then modify this file
to remove breadcrumbs take out line 14 which says
<?php bbp_breadcrumb(); ?>
then move line 44 (will probably be line 43 if you’ve taken out then breadcrumb!) which says
<?php bbp_get_template_part( 'form', 'reply' ); ?>
You may need to play with where to put it 9i haven’t tried it) , but after lines 21 & 22
<?php bbp_get_template_part( 'form', 'protected' ); ?> <?php else : ?>
looks a good start, if not just keep moving it til you get what you want.
If you only want it to look like this for the shortcode, then that is doable but a lot more complicated !
Thanks Robin! No problem with the steps you have laid out so far. How would I isolate these changes only for the shortcode?
ok so if your code savvy, two approaches
1. the hack
I haven’t tried this, but it should work fine
go into
wp-content/plugins/bbpress/includes/common/shortcodes.php
and look at line
355 which says
bbp_get_template_part( 'content', 'single-topic' );
change that to
bbp_get_template_part( 'content', 'single-topicb' );
That will then get bbpress looking for a php file called ‘content-single-topicb.php’
so then you can use the method in my first post to create that file in your theme ie as per first post, but just rename the file with a b at the end.
YOU WILL need to change this each time bbpress upgrades as it will overwrite – hence why it is the hack ! But that’s hardly difficult !
2. the proper way
Would be to create your own version of the shortcode, by copying all that particular shortcode into your themes functions file, BUT renaming it (or you’ll get already loaded errors), and then lots of editing to get it to work.
Personally I’d go route 1, and just make a note to change that file each time bbpress upgrades
I’m gonna stick with the first method seeing there’s just too much work for a simple hack. Thanks again for the help Robin, really appreciate it!
no problem !
Yikes I think I may have spoke a little too soon. Having done your recommended method, it doesn’t seem to isolate the changes made for the shortcode. I have removed the original modified file and created a duplicate named ‘content-single-topicb.php’. This corresponds with the change to line 335 in shortcodes.php with
bbp_get_template_part( 'content', 'single-topicb' );
.Any idea why it’s not working?
can you explain further?
Do you have the changes but all over the site, or do you not have the changes anywhere?
The modification does not limit to just the shortcode inclusion of the topic but on the forum as well. I thought it would have isolated but the changes seem to follow even on the default forum view?
It should work for just the shortcode, but let me test on my site
ok, interestingly (or not !) the forum code uses this shortcode.
Ok so plan b !
I’ve cut a quick new shortcode that looks for content-single-topicb.php
you can download it from my site
use the shortcode
[display-topic-special id=$topic_id]
Sorry Robin, where would I add that shortcode?
sorry, you need to put it at the end of your functions file
- You must be logged in to reply to this topic.