New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update QuickTags Documentation #13
Comments
@smileBeda, @audrasjb, and @tomjn from #357 Key points (See below for the changed contents)
Contens(Please also refer https://developer.wordpress.org/apis/quicktags/. Belows are just differences) Usage
Parameters...
ExamplesBelow examples would add HTML buttons to the default Quicktags in the Text editor. Traditional exampleThis example manually add hardcoded JavaScript with
Note:
The “p” button HTML would be:
The ID value for each button is automatically prepended with the string qt_content_. Modern exampleThis example uses the inline JS API to add the JavaScript when quicktags are enqueued.
Another Modern exampleIn this example,
Enqueue the scriptPut below codes into active theme's
The JavaScript itselfCreate new file
... Default QuicktagsHere are the values of the default Quicktags added by WordPress to the Text editor. ID must be unique. When adding your own buttons, do not use these values: (omitted. I will edit the table) |
@atachibana I would make one or two adjustments to the code examples The Traditional exampleThis version has:
/**
* Add more buttons to the quicktags HTML editor
*
* @return void
*/
function wporg_traditional_add_quicktags() {
if ( ! wp_script_is( 'quicktags' ) ) {
return;
}
?>
<script type="text/javascript">
QTags.addButton( 'eg_paragraph', 'p', '<p>', '</p>', '', 'Paragraph tag', 1, '', { ariaLabel: 'Paragraph', ariaLabelClose: 'Close Paragraph tag' } );
QTags.addButton( 'eg_hr', 'hr', '<hr />', '', '', 'Horizontal rule line', 201, '', { ariaLabel: 'Horizontal' } );
QTags.addButton( 'eg_pre', 'pre', '<pre lang="php">', '</pre>', '', 'Preformatted text tag', 111, '', { ariaLabel: 'Pre', ariaLabelClose: 'Close Pre tag' } );
</script>
<?php
}
add_action( 'admin_print_footer_scripts', 'wporg_traditional_add_quicktags', 11 ); Modern Example
/**
* Add a paragraph tag button to the quicktags toolbar
*
* @return void
*/
function wporg_add_quicktag_paragraph() {
wp_add_inline_script(
'quicktags',
"QTags.addButton( 'eg_paragraph_v2', 'p_v2', '<p>', '</p>', '', 'Paragraph tag v2', 2, '', { ariaLabel: 'Paragraph', ariaLabelClose: 'Close Paragraph tag' });"
);
}
add_action( 'admin_enqueue_scripts', 'wporg_add_quicktag_paragraph' ); |
@atachibana a final note, people are probably going to pick the example closest to the top and stick with that to save time reading through, so the modern example, aka the best example should be first. the traditional example if it's mentioned at all, should go further down the page. I'd even argue that it should be removed as of the 3 options it provides no benefits over the alternatives, and has multiple caveats. |
@tomjn Thank you so much for detailed adjustments! I would like to move Tradition Example to the end, not remove it, because the issue of Quicktags not working in WordPress 6.0 has caused so many problems I'd like to keep some explanation about it. Of course if everyone uses the Modern Example, we won't have this loading priority-dependent problem. |
Issue Description
This DOC's code example is outdated and suboptimal.
It should be updated to use a more modern approach.
I have already put a newer example on this page.
URL of the Page with the Issue
https://developer.wordpress.org/apis/handbook/quicktags/
Section of Page with the issue
https://developer.wordpress.org/apis/handbook/quicktags/#examples
Why is this a problem?
The first Problem is, the example shows to print a script instead of enqueueing it.
The second Problem is, it does not elaborate on the fact that any script trying to target those QuickTags has to be inside the call-back Function.
See my "More modern example" on the old codex.
Suggested Fix
Add this example along with the existing one (which is not wrong, it is just suboptimal and shouldn't be done like that if possible to avoid).
The text was updated successfully, but these errors were encountered: