Add custom styles to the WordPress editor (through manual and plug-in)

This will be executed as a convenient code snippet\/\/ Add custom styles to the WordPress editor
Function my\u custom\u styles ($init\u array){
$style_formats= arrays(
\/\/This is a custom style.
Sort(
\
\
\
\
),
Sort(
\
\
\
\
),
Sort(
\
\
\
\
),
);
\/\/JSON encoded array inserted into \
$init\u array[‘style\u formats’] = json\u encode ($style\u formats);
Return $init\u array;
}The
\/\/Connect the callback to \
Add\u filter (‘tiny\u mce\u before\u init’,’my\custom\u Styles’); To understand what’s going on here, let’s take a moment. The code snippet above is creating three different custom styles. In particular, we are adding the option to create highlighter pens for red buttons, content boxes, and text paragraphs. The
You can find it in the middle array. As you can see, each option is assigned a unique title, block, class, and scraper. Their meanings are as follows: Title – title sets the name of the custom style that appears in the drop-down menu. Block – defines the type of block element to be generated around the highlighted text, such as male, male, male. Existing block elements in the selection are replaced by new elements. Class – assign one or more classes to the selected element. Class is used to apply CSS styles to elements. Rapper – defines whether to add a container format to a block element, such as androg Rapper or blockquote. There are other parameters available (found in WordPress Codex). The
Inline – the name of the inline element to add to the selection. Similar to a block. Selectors – CSS 3 selector arrays apply classes to complex items, such as odd rows in a particular element or table. Useful for more subtle modeling applications. Style – allows you to directly add CSS styles as inline styles. Instead, you use CSS classes and style sheets to do this. Attributes – used to invoke new HTML attributes and apply them to selected elements or new inline \/ block elements. Precise – disables the ability to merge similar styles when used. This can be useful for some CSS inheritance issues. After adding the above code, the user-defined style must be displayed in the word press editor and the element assignment can begin. The
However, it will not change much until the corresponding CSS styles are defined. Fortunately, this is what we will do next. To see the effect of adding CSS styles and custom styles to the style sheet, you must first add CSS to the style sheet in the theme. In our case, you will see: Red button{
Background color: \bc3315;
-Moz border radius: 3px;
-Network kit border radius: 3px
;
Border radius: 3px;
Border: none;
Color: \fff;
Display: inline blocks;
Cursor: pointer;
Down jacket: 10px 30px;
Text decoration: none;
}The
Red button: hover{
Background color: \e53f19;
}The
Content block{
Border: 1px entity \ee;
Down jacket: 10px;
Background: \ccc;
Left
Margin – lower end: 1.75em;
Text alignment: Center;
}The
Content block: next{
Erase: both;
}The
Highlight{
Background color: \ffff66;
}As you can see, these styles are exactly the same as the classes previously assigned to user-defined elements. The style of the current topic. Once added to the CSS file, it is displayed on the front end of the site. The
Basically, this is the case. Adding custom styles to the WordPress editor is almost complete. But in fact, if you want to put cherries on top, you must go further. Currently, you must always switch back and forth between the editor and the page or page preview to ensure that custom styles are available. But wouldn’t it be better if the editor itself worked? I mean, is the result \
If you do not have this feature, you can directly implement the file at any time. Create a new text file and name editor styles. Just change it to CSS and copy the custom CSS styles into it. Then save and upload to the root directory of the topic or sub topic. Now, to make the theme use the new file, you can use the following code: All that’s left is to add to the PHP file. Function custom\editor\u styles(){
Add_editor_style (\
}The
Add\u action (\

Author:

Leave a Reply

Your email address will not be published. Required fields are marked *