I have the following code to remove toolbar, media buttons, and visual buttons on my wp_editor. The code is working, but I want it to only remove the items from one wp_editor, not all. Any help is appreciated.
Wp_editor code
$content = '';
$editor_id = 'message';
$settings = array(
'textarea_name' => 'message',
'textarea_rows' => 10,
);
wp_editor( $content, $editor_id, $settings );
Code to hide items
function my_format_TinyMCE( $in ) {
$in['toolbar1'] = '';
$in['toolbar2'] = '';
$in['toolbar'] = false;
return $in;
}
add_filter( 'tiny_mce_before_init', 'my_format_TinyMCE' );
add_filter( 'wp_editor_settings', function($settings) {
$settings['media_buttons']=FALSE;
$settings['quicktags']=FALSE;
return $settings;
});
You can set tinymce setting in editor settings
$content = '';
$editor_id = 'message';
$settings = array(
'textarea_name' => 'message',
'textarea_rows' => 10,
'tinymce' => array(
'toolbar1' => '',
'toolbar2' => '',
'toolbar3' => '',
),
);
wp_editor( $content, $editor_id, $args );
Related
what I want is that I have a special taxonomy and get_terms does not work without it being loaded, naturally the only way I can get it is to hook up to "init". But when this is the case, I will have to repeat this. I do not want this.
As you can see in the code below, I am doing the operation in init and trying to transfer it to "$ new_array". How can I do it?
protected function get_reactions()
{
$new_array = array();
add_action( 'init', function() use ( &$new_array ) {
$reactions = get_terms( array(
'taxonomy' => 'bp_reaction',
'hide_empty' => false
));
foreach ( $reactions as $value ) {
$priority = get_option( 'taxonomy_'.$value->term_id.'_priority' );
$image = get_option( 'taxonomy_'.$value->term_id.'_image' );
$new_array[$priority] = (object) array(
'id' => $value->term_id,
'priority' => $priority,
'slug' => $value->slug,
'name' => $value->name,
'image' => $image
);
}
}, 9 );
// Sort from largest to small
krsort( $new_array );
return $new_array;
}
I am a PHP beginner. I have trouble to making a basic if/then statement on function.
I add a woocommerce product tab 'Food_paring', I want to disable the tab when the field 'food_pairing" is empty/not set.
original code:
add_filter( 'woocommerce_product_tabs', 'new_product_tab' );
function new_product_tab( $tabs ) {
/* Adds the new tab */
$tabs['test_tab'] = array(
'title' => __( 'Food Pairing', 'woocommerce' ),
'priority' => 50,
'callback' => 'food_pairing_tab_content'
);
return $tabs; /* Return all tabs including the new New Custom Product Tab to display */
}
function food_pairing_tab_content() {
/* The new tab content */
echo '<h2>Food Pairing</h2><p id="tab-food-pairing">', get_post_meta( get_the_ID(), 'food_pairing', true ), '</p>';
}
Please check below code. Before add tab check if product meta has value or not global $post; if(get_post_meta($post->ID, 'food_pairing', true )){..}
add_filter( 'woocommerce_product_tabs', 'new_product_tab' );
function new_product_tab( $tabs ) {
global $post;
/* Adds the new tab */
if(get_post_meta($post->ID, 'food_pairing', true ))
{
$tabs['test_tab'] = array(
'title' => __( 'Food Pairing', 'woocommerce' ),
'priority' => 50,
'callback' => 'food_pairing_tab_content'
);
}
return $tabs; /* Return all tabs including the new New Custom Product Tab to display */
}
function food_pairing_tab_content() {
/* The new tab content */
echo '<h2>Food Pairing</h2><p id="tab-food-pairing">', get_post_meta( get_the_ID(), 'food_pairing', true ), '</p>';
}
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
global $woocommerce;
$tabs['desc_tab'] = array(
'title' => __( 'Ingredients', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content' ,
);
return $tabs;
}
function woo_new_product_tab_content() {
// The new tab content
echo '<p>Lorem Ipsum</p>';
echo $prod_id = get_the_ID();
echo'<p>'.get_post_meta($prod_id,'ingredients',true).'</p>';
}
this code is properly working... should try . Good Luck
I have a theme that extends the Visual Composer plugin with a slider on the front page. The slider will show five testimonials from five different customers. I want to add the featured image of each testimonial as the thumbnail in the slider.
Here's the shortened code from the parent theme:
function jo_customers_testimonials_slider( $atts ) {
extract( shortcode_atts( array( 'limit' => 5, "widget_title" => __('What Are People Saying', 'jo'), 'text_color' => "#000" ), $atts ) );
$content = "";
$loopArgs = array( "post_type" => "customers", "posts_per_page" => $limit, 'ignore_sticky_posts' => 1 );
$postsLoop = new WP_Query( $loopArgs );
$content = "";
$content .= '...';
$content .= '...';
$content .= '...';
wp_reset_query();
return $content;
}
add_shortcode( 'jo_customers_testimonials_slider', 'jo_customers_testimonials_slider' );
My functions.php file:
function jo_customers_testimonials_slider_with_thumbnail( $atts ) {
extract( shortcode_atts( array( 'limit' => 5, "widget_title" => __('What Are People Saying', 'jo'), 'text_color' => "#000" ), $atts ) );
$content = "";
$loopArgs = array( "post_type" => "customers", "posts_per_page" => $limit, 'ignore_sticky_posts' => 1 );
$postsLoop = new WP_Query( $loopArgs );
$content = "";
$content .= '...';
$content .= get_the_post_thumbnail( get_the_ID(), 'thumbnail' );
$content .= '...';
$content .= '...';
wp_reset_query();
return $content;
}
add_shortcode( 'jo_customers_testimonials_slider', 'jo_customers_testimonials_slider_with_thumbnail' );
In theory, the function from my functions.php file should overwrite the shortcode from the parent theme. But nothing seems to happen when I use this code. What am I doing wrong?
Edit:
Tried this code, but it still won't work.
function wpa_add_child_shortcodes(){
remove_shortcode('jo_customers_testimonials_slider');
add_shortcode( 'jo_customers_testimonials_slider', 'jo_customers_testimonials_slider_with_thumbnail' );
}
add_action( 'after_setup_theme', 'wpa_add_child_shortcodes' );
Also changed
add_action( 'after_setup_theme', 'wpa_add_child_shortcodes' ); to
add_action( 'init', 'wpa_add_child_shortcodes' );
, but no difference in the outcome.
Edit 2 (With Solution):
Changing add_action( 'after_setup_theme', 'wpa_add_child_shortcodes' ); to add_action( 'wp_loaded', 'wpa_add_child_shortcodes' ); solved it.
you need to call remove_shortcode(); like this:
remove_shortcode('jo_customers_testimonials_slider');`
Before you add your new shortcode with the same name to "overwrite" it.
You'll also need to call it after the parent theme has run so we fire on an action hook called wp_loaded.
function overwrite_shortcode() {
function jo_customers_testimonials_slider_with_thumbnail($atts) {
extract(shortcode_atts(array('limit' => 5, "widget_title" => __('What Are People Saying', 'jo'), 'text_color' => "#000"), $atts));
$content = "";
$loopArgs = array("post_type" => "customers", "posts_per_page" => $limit, 'ignore_sticky_posts' => 1);
$postsLoop = new WP_Query($loopArgs);
$content = "";
$content .= '...';
$content .= get_the_post_thumbnail(get_the_ID(), 'thumbnail');
$content .= '...';
$content .= '...';
wp_reset_query();
return $content;
}
remove_shortcode('jo_customers_testimonials_slider');
add_shortcode('jo_customers_testimonials_slider', 'jo_customers_testimonials_slider_with_thumbnail');
}
add_action('wp_loaded', 'overwrite_shortcode');
You have to write this code in your Child Theme's functions.php
add_action( 'after_setup_theme', 'calling_child_theme_setup' );
function calling_child_theme_setup() {
remove_shortcode( 'parent_shortcode_function' );
add_shortcode( 'shortcode_name', 'child_shortcode_function' );
}
function child_shortcode_function( $atts) {
$atts = shortcode_atts( array(
'img' => '',
'cat' => '',
'capt' => '',
'link' => ''
), $atts );
//YOUR OWN CODE HERE
$imgSrc = wp_get_attachment_image_src( $atts['img'], 'delicious-gallery' );
$imgFull = wp_get_attachment_image_src( $atts['img'], 'full' );
$b = '<div class="screen-item" data-groups=\'["'.strtolower(str_replace(' ', '_', $atts["cat"])).'", "all"]\'>'.
'<img src="'.$imgSrc[0].'" alt="SCREEN" class="screenImg" />'.
'<span>'.$atts["capt"].'</span>'.
'</div>';
//YOUR OWN CODE HERE
return $b;
}
Here's a shortcode of mine:
function sc_link( $atts ) {
extract( shortcode_atts(
array(
'page' => '',
'style' => 'button',
'window' => 'self',
'label' => 'Missing Label Tag: label=""',
), $atts )
);
return '' . $label . '';
}
add_shortcode( 'mylink', 'sc_link' );
What I want to be able to do is a conditional before the return: if $window = 'new' then echo 'blank'.
Think this is what your trying to do what id suggest doing is leaving window blank and just doing an if statement on that
How you want it
function sc_link( $atts ) {
extract( shortcode_atts(
array(
'page' => '',
'style' => 'button',
'window' => 'self',
'label' => 'Missing Label Tag: label=""',
), $atts )
);
if($window == "new"){
$link = '' . $label . '';
}else{
$link = '' . $label . '';
}
return $link;
}
add_shortcode( 'mylink', 'sc_link' );
How it should be
function sc_link( $atts ) {
extract( shortcode_atts(
array(
'page' => '',
'style' => 'button',
'window' => '',
'label' => 'Missing Label Tag: label=""',
), $atts )
);
if(!$window){
$link = '' . $label . '';
}else{
$link = '' . $label . '';
}
return $link;
}
add_shortcode( 'mylink', 'sc_link' );
The your shortcode will be link
[shorcode page="" window="" label=""]
Here is an easy short code conditional output example. I would recommend being sparing with this type of syntax because it can get lost in the fray.
echo ($window === 'new') ? $window : '';
This format is conditional ? what to do if true : what to do if false
I am trying to figure out how to remove specific buttons from the TinyMCE editor. I have researched the arguments in the codex but for TinyMCE is just says array and not sure if I can include some paramters in my arguments of which buttons to show/hide?
I am using the editor in a gravity form and my code is as follows so far
add_action( 'gform_field_input', 'gforms_wp_editor', 10, 5 );
function gforms_wp_editor( $input, $field, $value, $lead_id, $form_id ) {
if( $field["cssClass"] == 'richtext' ) {
ob_start();
wp_editor( $value, "input_{$form_id}_{$field['id']}",
array(
'media_buttons' => false,
'quicktags' => false,
'textarea_name' => "input_{$field['id']}"
) );
$input = ob_get_clean();
}
return $input;
}
I have removed the HTML tab using the quicktags to false, so hoping I can do something similar to strip out buttons from the editor.
buttons shown right now with the code above are as follows
Note: 'teeny' editor is now what I need, just in case someone suggests
Thanks
The tinymce parameter allows you to pass configuration options directly to TinyMCE - see the docs for theme_advanced_buttons and theme_advanced_disable, and the button reference.
To show only the bold, italic and underline buttons:
wp_editor($value, "input...", array(
'tinymce' => array(
'theme_advanced_buttons1' => 'bold,italic,underline',
'theme_advanced_buttons2' => '',
'theme_advanced_buttons3' => ''
)
));
Or, to show everything except the bold, italic and underline buttons:
wp_editor($value, "input...", array(
'tinymce' => array(
'theme_advanced_disable' => 'bold,italic,underline'
)
));
As requested, your code modified:
add_action( 'gform_field_input', 'gforms_wp_editor', 10, 5 );
function gforms_wp_editor( $input, $field, $value, $lead_id, $form_id ) {
if( $field["cssClass"] == 'richtext' ) {
ob_start();
wp_editor( $value, "input_{$form_id}_{$field['id']}",
array(
'media_buttons' => false,
'quicktags' => false,
'textarea_name' => "input_{$field['id']}",
'tinymce' => array(
'theme_advanced_disable' => 'bold,italic,underline'
)
)
);
$input = ob_get_clean();
}
return $input;
}