Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am developing a theme and using jquery prettify to style code tags. Sofar I love prettify, and for the most part wordpress is cooperating.

When text is wrapped in <code> tags everything works dandy. But on certain editors, and the bbpress topic / reply / edit , editor the code is wrapped in the the little dash marks just like on these forums, and sometimes the code gets all mangled.

What I am looking to do is force every editor on my wordpress install , or atleast the code buttons on the editor to wrap code in tags instead of the little dash marks. I have looked at some filters but sofar i do not see how to change the output or behavior of the tiny mce fancy editor buttons thats standard with wordpress.

Thanks for any direction or suggestions.

share|improve this question

1 Answer 1

up vote 0 down vote accepted
+50

put this code in functions.php

add_action('wp_footer','ravs_codeTag_fix');
function ravs_codeTag_fix(){
    if ( bbp_use_wp_editor() ) :
    ?>
    <script>
        jQuery(document).ready( function() {

            /* Use <code> instead of backticks for the Code button in the editor */
            if ( typeof( edButtons ) !== 'undefined' ) {
                edButtons[110] = new QTags.TagButton( 'code', 'code', '<code>', '</code>', 'c' );
                QTags._buttonsInit();
            }
        });
    </script>
    <?php
    endif;
}

Note:

bbpress plugin overwrites the code button behaviour ( of wordpress editor ) by putting some script in head.You can find this script in bbpress->templates->default->bbpress-functions.php online 219

Updated:

1).If you want to customize wordpress editor then you can explore it by going throw WordPress QuickTags API (quicktags.js) and Tinymce WordPress codex.These documention also have good tutorial link which guide you practically.

2).You can use WordPress Plugin AddQuicktag for editing WordPress Editor.This plugin make it easy, Quicktags add to the html - and visual-editor.. It is possible to ex- and import your Quicktags.

Edited:

paste below code in functions.php.

add_filter( 'bbp_new_topic_pre_content',  'ravs_bbp_code_trick', 10);
add_filter( 'bbp_new_reply_pre_content',  'ravs_bbp_code_trick', 10);
add_filter( 'bbp_new_forum_pre_content',  'ravs_bbp_code_trick', 10);
add_filter( 'bbp_edit_topic_pre_content',  'ravs_bbp_code_trick', 10);
add_filter( 'bbp_edit_topic_pre_content',  'ravs_bbp_code_trick', 10);
add_filter( 'bbp_edit_forum_pre_content',  'ravs_bbp_code_trick', 10);
function ravs_bbp_code_trick( $content ){
    $pattrens[0]='/<code>/';
    $pattrens[1]='/<\/code>/';
    $content = preg_replace( '/\`/','backtick_place', $content );
    $content = preg_replace( $pattrens,'`', $content );
    return $content;
}
add_filter('bbp_get_topic_content','ravs_bbp_prevent_trick',51);
add_filter('bbp_get_reply_content','ravs_bbp_prevent_trick',51);
add_filter('bbp_get_form_forum_content','ravs_bbp_prevent_trick',51);
function ravs_bbp_prevent_trick($content){
    $content = preg_replace( '/backtick_place/','`', $content );
    return $content;
}
share|improve this answer
    
excellent, I will implement this and accept the answer if it works when I get a chance. If possible could you describe the ed buttons[] array and the QTags.TagButton() functon briefly so I can attempt to implement my own solutions in the future? –  Ronburgundy Jul 17 '13 at 16:06
    
Answer updated, check it.Code in answer is test with bbpress.ed_buttons is a object while QTags is function. –  Ravs Jul 17 '13 at 17:13
    
The function now correctly changes the output of the code button to be <code> but now wordpress, or bbpress more so does not display the information correctly. When using backticks the code is displayed fine, but when using <code> bbpress seems to inject closing tags in wierd places breaking it all up, or it just not preserve the code and outputs it as if it were html (testing with html code) –  Ronburgundy Jul 17 '13 at 21:51
    
Ive accepted your answer, as it does what i asked, but does not function how I wish it functioned... –  Ronburgundy Jul 18 '13 at 2:18
    
wihthout seeing your test it's difficult to tell what's wrong.do you have live test site? –  Ravs Jul 18 '13 at 6:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.