Add a style selector to the WordPress Post Editor
The toolbar (known as the kitchen sink – don’t ask me why!) is where you can style your post by assigning heading tags, creating lists, aligning text and all other lovely things. What you can also do is assign your own styles by adding classes to sections of text. Find out how now.
The toolbar (known as the kitchen sink – don’t ask me why!) is where you can style your post by assigning heading tags, creating lists, aligning text and lots more. You can also assign your own styles by adding classes to text. Add the following function to your theme’s functions.php file and add as many css selectors as you like. I’ve added “Intro” and “Link style” to this example. You need to add the title i.e. Link style and then css class i.e. linkstyle.
You can then find this new dropdown selector in your kitchen sink with the dropdown name of “Styles”. All you then need to do is select the text you wish to style and choose the selector from the dropdown. The text isn’t styled in the editor but will be on your site, assuming you’ve added a style to that class in your theme’s stylesheet.
// Add CSS Class to Edit Screen
add_filter( 'tiny_mce_before_init', 'my_custom_tinymce' );
function my_custom_tinymce( $init ) {
$init['theme_advanced_buttons2_add_before'] = 'styleselect';
$init['theme_advanced_styles'] = 'Intro=intro,Link style=linkstyle';
return $init;
}
Another useful little function to add is this:
// Show Kitchen Sink to all WP Admin users
function unhide_kitchensink( $args ) {
$args['wordpress_adv_hidden'] = false;
return $args;
}
add_filter( 'tiny_mce_before_init', 'unhide_kitchensink' );
This will then show the kitchen sync to add admin users. For some reason the second row in the kitchen sink is not shown by default, which is odd as this is where the most useful selectors are.
One reply on “Add a style selector to the WordPress Post Editor”
Leave a Reply
-
Free up space on your Mac
You may not know it but there’s a lot of places on your shiny lovely Mac that can store lots of rubbish that you don’t actually need. We’ll explain a few places you can look to see if there’s a mass of files that you can safely delete and free up a few valuable gigs of space.
-
iPhone to Mac Wireless Networking
Connect to your jailbroken iPhone to your Mac to add or retrieve files and folders.
-
Is your site LIVE? FREE website monitoring sites
Keep a check on whether your website is live with these free and paid for tools.
-
Disable Flash in Chrome on Mac and PC
Sometimes you need to disable Flash. Maybe to test sites that run in both Flash and HTML and therefore automatically show you to the Flash elements or maybe you just don’t want Flash running in your browser. Whatever it is then here’s how to disable it in Chrome on a Mac.
-
Add category description if it exists
Find out how to add the category description to your category template in Wordpress.
-
iPhone Jailbreak for OS 3.0 Released
How to jailbreak your iPhone.
-
Backing up your Website using cPanel
Find out how to back up your website via cPanel
-
Domain Extensions. Are they important?
Does it make any difference what domain extension you choose? Find out more.
-
Web Browsing Tips #2: Tabbed Windows
Using tabbed windows in your web browser.
-
What's in a name? Choosing the right name for your company and website
Find out how to choose a great company name with a few basic tips.
-
Web Browsing Tips #3: Keyboard Shortcuts
Some web browsing keyboard shortcuts.
-
WordPress Login / Logout Link in Template
The standard Wordpress Login/Logout links often suffice but when you are building custom pages then the default Wordpress pages can look a little out of place on your site and therefore you may need to redirect your users to different pages and/or change the text links of those standard links.
Thanks, it works fine!