n3wjack (@n3wjack)

Forum Replies Created

Viewing 1 replies (of 1 total)

  • n3wjack
    Participant

    @n3wjack

    What I do in this case is use client side JavaScript code to inject a new HTML element at the position you want it, with your custom code.
    I put a Custom HTML widget on the page which has all the required JS & CSS code.
    The advantage of this approach is that you don’t need to mess with the PHP files of your WordPress or bbPress setup, so when you do an upgrade in the future, you don’t have to worry about your changes being overwritten, or your site to break because of your changes.

    I use the code below to place a Reply button on top of the page. When it’s clicked, it will scroll down to the new post form at the bottom of the page (the most recent post is on top).

    <script type="text/javascript">
    	// Add the reply shortcut button at the top.
    	let btn = document.createElement("a");
        btn.href='javascript:document.getElementsByClassName("bbp-footer")[0].scrollIntoView()'	
    
    	btn.innerText='Reply'
    	btn.className='nj-replybtn'
    
    	let n = document.getElementsByClassName('bbp-replies')[0];
    
    	if (n !== null) {  
    		n.parentNode.insertBefore(btn, n);
    	}
    
    </script>
    <style>
    	.nj-replybtn {
    		color: white;
    		background-color: #007acc;
    		
    		padding: 5px;
    		margin: 2px;
    	}
    </style>
Viewing 1 replies (of 1 total)