Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding a line of text above/below each topic

Viewing 21 replies - 1 through 21 (of 21 total)

  • wpturk
    Participant

    @wpturk

    This would do the job. Put this in your functions.php and replace the text.

    function add_custom_content($content) {
        
        $before ="<p>TEXT BEFORE</p>";
        $after ="<p>TEXT AFTER</p>";
        $content = $before . $content . $after;
        return $content;
    }
    add_filter ('bbp_get_topic_content', 'add_custom_content'); 

    Beautiful!

    Actually, I forgot something. How to apply this function only to the key master, not the participants?


    wpturk
    Participant

    @wpturk

    Here we go:

    function add_custom_content($content) {
    
        $topic_id = bbp_get_topic_id();
        $user_id = bbp_get_topic_author_id( $topic_id );
    
        if ( bbp_is_user_keymaster($user_id) ) {
    
                $before ="<p>TEXT BEFORE</p>";
                $after ="<p>TEXT AFTER</p>";
                $content = $before . $content . $after;
        }
        return $content;
    }
    add_filter ('bbp_get_topic_content', 'add_custom_content');

    Thank you!


    wpturk
    Participant

    @wpturk

    you are welcome πŸ‘


    enkoes
    Participant

    @enkoes

    Hi, do u know how to center the text?

    I try <p style=”text-align:center”>TEXT</p> but not working.


    wpturk
    Participant

    @wpturk

    you have to be careful with the Quotation marks, try:

    $before ='<p style="text-align:center">TEXT BEFORE</p>';


    enkoes
    Participant

    @enkoes

    Thanks for yr guidance. It finally works! πŸ™‚


    wpturk
    Participant

    @wpturk

    you are welcome.

    Hi,

    I use the Post Comments as bbPress Topics plugin, which gives by default an excerpt of the concerned post. None of the other options seem to work but none of them suit me either. Expanding on the php code you gave earlier in this thread, would it be possible to simply delete all content in the topic other than “[See the full post at: …]” and, of course, my own [TEXT]?

    Thank you


    wpturk
    Participant

    @wpturk

    Hi, I’ve not used this plugin so I don’t know how it works.

    Maybe the plugin is using the WordPress excerpt, you can try this:

    add_filter( 'the_excerpt', 'filter_the_excerpt', 10, 2 );
        function filter_the_excerpt( ) {
        return ' ';
     }

    No, that doesn’t do anything. I asked the question to the plugin author a few days ago but got no answer. One last request regarding the code you gave me earlier on: How can I insert an external link in my [TEXT]?


    wpturk
    Participant

    @wpturk

    You can change the $before and $after variables to whatever you like. For example an external link before all topics:

    function add_custom_content($content) {
    
        $topic_id = bbp_get_topic_id();
        $user_id = bbp_get_topic_author_id( $topic_id );
    
        if ( bbp_is_user_keymaster($user_id) ) {
    
                $before ='<p>This is my <a href="https://bbpress.org/">EXTERNAL LINK</a>.</p>';
                $after ='<p>TEXT AFTER</p>';
                $content = $before . $content . $after;
        }
        return $content;
    }
    add_filter ('bbp_get_topic_content', 'add_custom_content');

    For the excerpt issue you can give a try with another priority:

    function filter_the_excerpt( ) {
        return ' ';
    }
    add_filter( 'the_excerpt', 'filter_the_excerpt', 999, 2 );

    So, I did the following because I want the word “here” to hold the external link. I messed up, of course:
    function add_custom_content($content) {

    $topic_id = bbp_get_topic_id();
    $user_id = bbp_get_topic_author_id( $topic_id );

    if ( bbp_is_user_keymaster($user_id) ) {

    $after =”<p><i>Still struggling with your website(s) speed? Click here.</i></p>”;
    $content = $before . $content . $after;
    }
    return $content;
    }
    add_filter (‘bbp_get_topic_content’, ‘add_custom_content’);


    wpturk
    Participant

    @wpturk

    you have to be careful with the quotation marks:

    function add_custom_content($content) {
    
        $topic_id = bbp_get_topic_id();
        $user_id = bbp_get_topic_author_id( $topic_id );
    
        if ( bbp_is_user_keymaster($user_id) ) {
    
                $after ='<p><i>Still struggling with your website(s) speed? Click <a href="https://example.com/">here</a>.</i></p>';
                $content = $content . $after;
        }
        return $content;
    }
    add_filter ('bbp_get_topic_content', 'add_custom_content');

    Thank you! Each time I try by myself and each time I get stuck. My fat fingers do not know how to make the word “here” bold and its link open in another tab. This is something I’ve done dozens of times but it won’t work in this php coding. Thanks again, doctor.


    wpturk
    Participant

    @wpturk

    πŸ™‚

    function add_custom_content($content) {
    
        $topic_id = bbp_get_topic_id();
        $user_id = bbp_get_topic_author_id( $topic_id );
    
        if ( bbp_is_user_keymaster($user_id) ) {
    
                $after ='<p><i>Still struggling with your website(s) speed? Click <strong><a href="https://example.com/" target="_blank">here</a></strong>.</i></p>';
                $content = $content . $after;
        }
        return $content;
    }
    add_filter ('bbp_get_topic_content', 'add_custom_content');

    The target=”_blank” does not work. If it is just that, I can put it on the IT gods’ malevolence and live with it.


    wpturk
    Participant

    @wpturk

    Probably, your theme or one of your plugin is already modifying external links to add “nofollow” attributes etc … and simultaneously breaking target="_blank" … Difficult to say before checking your theme and all your plugins. I would remove target="_blank" if it’s not working.

    That’s good to know. I will enquire a bit further.

Viewing 21 replies - 1 through 21 (of 21 total)
  • You must be logged in to reply to this topic.
Skip to toolbar