I've added some div wrapper styles to Wordpress, but when I use them in the page, it is impossible to add content below them in the page. CSS:after works inside the divs to create a selectable area, but it doesn't work to create a selectable area after the div.
In my functions.php I have:
function my_mce_before_init( $settings ) {
$style_formats = array(
array(
'title' => 'Box Two Columns',
'block' => 'div',
'classes' => 'twocolbox',
'wrapper' => true
),
array(
'title' => 'Image with Caption',
'block' => 'div',
'classes' => 'img_caption',
'wrapper' => true
),
array(
'title' => 'Gallery Horizontal',
'block' => 'div',
'classes' => 'scroller horizontal',
'wrapper' => true
)
);
$settings['style_formats'] = json_encode( $style_formats );
return $settings;
}
add_filter('tiny_mce_before_init', 'my_mce_before_init');
add_editor_style();
Is there a way to use execCommand here to add some html after the div styles I defined? To add something like an empty paragraph tag afterwards with a clear float?
I tried:
tinyMCE.execCommand('mceInsertContent',false,'Hello world!!');"
MCE editor breaks then.
...
Tried this but it's too buggy:
In editor-styles.css:
#tinyMCE:after {
content: " ";
clear:both;
width: 4em; height:4em;
}
Note that you may need to clear cache AND shift-reload button to see any changes to editor-styles.css in Wordpress.
...
Still working on this. Found a thread:
To access tinymce iframe elements through jquery
I tried adding the code in this thread to my_mce_before_init, but it just broke.
....
Also tried loading a jQuery script, but the target paths wouldn't work on the TinyMCE iframe. None of these selectors work:
jQuery(document).ready(function($) {
$("#tinyMCE").find("div").after('<p style="width:100%; clear:both; height:1em;"> 6789</p>');
$("div").css("color","red");
$("#content_ifr").contents().find("div").after('<p style="width:100%; clear:both; height:1em;"> 6789</p>');
$("#content_ifr").contents().find("#tinymce p").css("color","red");
$("#wp-content-editor-container").find("textarea").css("color","red");
$("iframe").contents().find("p").css("color","red");
$('#content_ifr').load(function(){
$('#content_ifr').contents().find('p').css("color","red");
});
});
You can add html pseudo elements using the tinymce configuration option content_css.
There you can define after elements. Give it a try!
Update:
When initializing tinymce set the setup paramter to the following (inside tinyMCE.init({...})
...
theme: "advanced", // example param
setup : function(ed) {
ed.onInit.add(function(ed, evt) {
$("#content_ifr").contents().find("p").css("color","red");
// other approach
//$(ed.getBody()).find('p').css("color","red");
});
},
cleanup: true, // example param
...
Related
I have created a new TinyMCE layout for Advanced Custom Fields called "Very Simple" that I want to use on specific WYSIWYG fields. I've managed to add the buttons I want and I'm now looking for a way to add a list of custom style formats as a dropdown, but I can't really figure out how to do this.
The code I have right now is the following:
// Customize ACF MCE
add_filter( 'acf/fields/wysiwyg/toolbars' , 'new_toolbars' );
function new_toolbars( $toolbars )
{
// - this toolbar has only 1 row of buttons
$toolbars['Very Simple' ] = array();
$toolbars['Very Simple' ][1] = array('bold' , 'italic' , 'underline', 'link', 'unlink' );
$style_formats = array(
// These are the custom styles
array(
'title' => 'Red Button',
'block' => 'span',
'classes' => 'red-button',
'wrapper' => true,
),
array(
'title' => 'Content Block',
'block' => 'span',
'classes' => 'content-block',
'wrapper' => true,
),
array(
'title' => 'Highlighter',
'block' => 'span',
'classes' => 'highlighter',
'wrapper' => true,
),
);
// Insert the array, JSON ENCODED, into 'style_formats'
$toolbars['Very Simple'][1]['styleselect'] = json_encode( $style_formats );
// return $toolbars - IMPORTANT!
return $toolbars;
}
The style format dropdown is not showing. Any ideas why?
The styleselect dropdown is hidden by default, so to get any registered formats/styles will show, you'll just need to activate the styleselect dropdown menu in the Visual editor.
The below function (from the WordPress Codex) filters the array of buttons loaded by TinyMCE, so just add this to your functions.php. I'm using the mce_buttons_2 filter to make it appear in the second row of my toolbar.
// Callback function to insert 'styleselect' into the $buttons array
function my_mce_buttons_2( $buttons ) {
array_unshift( $buttons, 'styleselect' );
return $buttons;
}
// Register our callback to the appropriate filter
add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );
I've been reading the WordPress codex on adding custom background options, like in this example
$defaults = array(
'default-color' => '',
'default-image' => '',
'default-repeat' => '',
'default-position-x' => '',
'default-attachment' => '',
'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => ''
);
add_theme_support( 'custom-background', $defaults );
The generated output then looks exactly like this:
<style type="text/css" id="custom-background-css">
body.custom-background { background-color: #bdd96e; }
</style>
This won't work because of the complexity of my theme, i need to be able to change the above snippet so it will override the default background for .menu-wrapper tag, is there a way I can change the default CSS selector to target a different tag instead of body?
What is in the callback function _custom_background_cb? Is that part of core WP?
I'm completely guessing here but I think you'll want to define a function that is called to return the output you want. You'll need to adjust for admin-head-callback, & admin-preview-callback too.
Try something like this but you might need to do some research on the callback parameters.
$defaults = array(
// ...
'wp-head-callback' => 'my_custom_function',
// ...
);
add_theme_support( 'custom-background', $defaults );
function my_custom_function()
{
$html = "<style type="text/css" id="custom-background-css">";
$html += " #my-selector { background-color: #bdd96e; }";
$html += "</style>";
return $html;
}
I'm customizing my Customization options in a WordPress theme following a video from awfulmedia (http://www.youtube.com/watch?v=XloM1F5M2fU). It's very good, but I've got one hang up.
function martinStart_footer_customizer_register($wp_customize) {
$wp_customize->add_section('footer_styles', array(
'title' => __('Footer Styles', 'martinStart'),
'description' => 'Modify Footer Styles'
));
$wp_customize->add_setting('footer_background', array(
'default' => '#CCC',
));
$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'footer_background_ctrl', array(
'label' => __('Footer Background Color', 'martinStart'),
'section' => 'footer_styles',
'settings' => 'footer_background'
) ));
}
function martinStart_footer_style() {
?>
<style type="text/css">
.site-footer {background-color: <$php echo get_theme_mod('footer_background'); ?>;}
</style>
<?php
}
add_action('wp_head', 'martinStart_footer_style');
add_action('customize_register', 'martinStart_footer_customizer_register');
So I use the Wordpress custom_color_control and the color change is saved in the wp_options table, and style declaration is added to the head.
But the value isn't added, it writes the php code! Can anyone see what I'm doing wrong?
php code most be surrounded by <?php code ?>, but the code in question begins with <$php. You need to replace the $ with a ?.
Initial issue:
My client wanted an custom HTML rendering sidebar widget for their wordpress site. I created a simple one that allows them to choose the color (class switching) and gives them a textarea to put their HTML into. Now they have requested a basic WYSIWYG interface attached to it (CKEditor or TinyMCE) but I dont know how to add it to the textarea inside the widget code. Does anyone know how, have an example, or a place to see how it can work? Thanks!
EDIT (After use of wp_editor):
So I have my code to this point but the editor is disabled and not able to be used. Any ideas why?
<fieldset>
<label>Enter your HTML</label>
<?php
$settings = array(
'wpautop' => true,
'media_buttons' => false,
'tinymce' => array(
'theme_advanced_buttons1' => ',bold,italic,underline,|,link,unlink',
),
'quicktags' => false
);
$bodyID = $this->get_field_id('body');
$content = '';
wp_editor($content, $bodyID, $settings );
?>
</fieldset>
Use wp_editor function, your code will look something like this:
http://codex.wordpress.org/Function_Reference/wp_editor
<fieldset>
<label> Your label for the text area </label>
<?php
$settings = array(
'wpautop' => true,
'media_buttons' => false,
'tinymce' => array(
'theme_advanced_buttons1' => 'formatselect,|,bold,italic,underline,|,' .
'bullist,blockquote,|,justifyleft,justifycenter' .
',justifyright,justifyfull,|,link,unlink,|' .
',spellchecker,wp_fullscreen,wp_adv ',
),
'quicktags' => false
);
wp_editor('initial content', 'id of textarea', $settings );
?>
</fieldset>
Note that if you want to put the content in the WP database from front end you should use in addition wp_insert_post function and a POST varible as a link.
My problem: the two pagination options are on separate lines.
I have:
<div class="search_result searchconright">
<?php
$this->widget('zii.widgets.CListView', array(
'id' => 'listViewSearch',
'dataProvider' => $model->search(),
'itemView' => '_index_post',
'enablePagination' => true,
'pager' => array(
'cssFile' => Yii::app()->baseUrl . '/css/clistview.css',
'header' => false,
'firstPageLabel' => 'First',
'prevPageLabel' => 'Previous',
'nextPageLabel' => 'Next',
'lastPageLabel' => 'Last',
),
'summaryText' => '',
'sortableAttributes' => array(
),
));
?>
</div>
<div class="pagetxt">
<span>View</span>
<a class="page_search_limit">All</a>
<a class="page_search_limit page_search_limit_active">3</a>
<a class="page_search_limit page_search_limit_active">5</a>
<a class="page_search_limit page_search_limit_active">24</a>
<a class="page_search_limit">48</a>
</div>
and i would like to insert the entire html from class pagetxt in the widget, because the seccond pagination, is under the widgets pagination; i would like them to be on the same line
also, other suggestions are welcomed
the pagination:
You have 2 options, first the way you are doing it, you can use the template property of CListView, to add the HTML where you want inside the widget.
But It looks like what you are trying to do, is to allow the user to specify the number of elements they want to see per page, so I'd recommend to use something like the PageSize extension
I think you can do this with CSS:
.search_result, .pagetxt {
display: inline-block;
}
To change the CListView pagination HTML, you would have to create a new CLinkPager and the pass parameters to it. So I think CSS is way simpler :)
This is purely a layout issue: you need to have the pager render inline with your custom HTML.
One way to do that would be to give display: line-block to both of these DIVs with CSS, but of course you can also use other techniques like floating.
You can easily target the stock pager by setting the pagerCssClass property on your list view; the default is simply "pager", so you could do
$this->widget('zii.widgets.CListView', array(
'id' => 'listViewSearch',
'pagerCssClass' => 'pager pager-inline'
// ...
);
and then for example
.pager.pager-inline, .pagetxt {
display: inline-block;
}