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;
}
Related
I am working with ACF Pro and ACF Theme Code Pro plugins.
It correctly working within admin-panel but not working on site.
Maybe anyone know what i doing incorrectly?
my functions.php
add_action( 'acf/init', 'register_about_service_block' );
function register_about_service_block() {
if ( function_exists( 'acf_register_block_type' ) ) {
// Register About service block
acf_register_block_type( array(
'name' => 'about-service',
'title' => __( 'About service' ),
'description' => __( 'A custom About service block.' ),
'category' => 'formatting',
'icon' => 'layout',
'keywords' => array( 'about', 'service' ),
'post_types' => array( 'post', 'page' ),
'mode' => 'auto',
// 'align' => 'wide',
'render_template' => 'template-parts/blocks/about-service.php',
// 'render_callback' => 'about_service_block_render_callback',
'enqueue_style' => get_template_directory_uri() . '/dist/css/services.min.css',
// 'enqueue_script' => get_template_directory_uri() . '/template-parts/blocks/about-service/about-service.js',
// 'enqueue_assets' => 'about_service_block_enqueue_assets',
));
}
}
Plugin genereted code that i can use in my template. I use it in template and it correctly working in admin-panel. It looks like this
But on my page, where i use this template it not working. Еhe template itself is connected correctly.
function acf_register_block_type must return $block
function acf_register_block_type( $block ) {
// Validate block type settings.
$block = acf_validate_block_type( $block );
// Bail early if already exists.
if( acf_has_block_type($block['name']) ) {
return false;
}
// Add to storage.
acf_get_store( 'block-types' )->set( $block['name'], $block );
// Register block type in WP.
if( function_exists('register_block_type') ) {
register_block_type($block['name'], array(
'attributes' => acf_get_block_type_default_attributes(),
'render_callback' => 'acf_rendered_block',
));
}
// Register action.
add_action( 'enqueue_block_editor_assets', 'acf_enqueue_block_assets' );
// Return block.
return $block;
}
Then $block must be use in my template but when i make var_dump($block) i get null. Hence i can't use data by $block in template
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 );
So I ran into a issue where the customizer preview doesn't fully refresh. Only when I manually refresh the page I see my changes. Some of my code to help explain below.
For my customizer settings I have code that looks something like this
$wp_customize->add_section( 'theme_layout', array(
'title' => __( 'Layout', 'theme' ),
'priority' => 30
) );
$wp_customize->add_setting( 'theme_header_layout', array(
'default' => 'default',
'transport' => 'refresh',
) );
$wp_customize->add_control( new WP_Customize_Control( $wp_customize,
'theme_header_layout', array(
'label' => __( 'Header', 'theme' ),
'section' => 'theme_layout',
'settings' => 'theme_header_layout',
'type' => 'select',
'choices' => array(
'default' => 'default',
'special_header' => 'Special Header',
)
) ) );
Now In my functions.php I have code like this
//this is the code that doesn't seem to execute when the customizer refreshes
if ( 'special_header' == get_theme_mod( 'theme_header_display' ) ):
function theme_special_header( $items ) {
$items .= do_shortcode('[special_header_shortcode]');//This shortcode exists I just didnt bother mentioning it here
}
add_action( 'wp_nav_menu_secondary-menu_items', 'theme_special_header' );//Adds shortcode to menu with id of secondary-menu
endif;
This all works great accept when I go to the customizer and select 'Special Header' the customizer refreshes and I don't see my changes until I completely refresh the page.
I had also faced similar issue earlier. Rather than adding conditional outside, I kept it inside the function and it worked. You can try similar approach for your code and it may help.
Following is not exact answer for your question but it may help to fix your problem.
function wpso_customize_menu($items, $args) {
if ( 'special_header' == get_theme_mod( 'theme_header_layout' ) ) {
if( $args->theme_location == 'menu-1' ) {
$items .= '<li>Custom Link</li>';
}
}
return $items;
}
add_filter('wp_nav_menu_items', 'wpso_customize_menu', 10, 2);
I am looking to make some modifications to a function in WooCommerce, on a file called class-wc-frontend-scripts.php in woocommerce/includes/
The function I'm looking to modify is:
private static function get_script_data( $handle ) {
global $wp;
switch ( $handle ) {
case 'wc-single-product' :
return array(
'i18n_required_rating_text' => esc_attr__( 'Please select a rating', 'woocommerce' ),
'review_rating_required' => get_option( 'woocommerce_review_rating_required' ),
'flexslider' => apply_filters( 'woocommerce_single_product_carousel_options', array(
'rtl' => is_rtl(),
'animation' => 'slide',
'smoothHeight' => true,
'directionNav' => false,
'controlNav' => 'thumbnails',
'slideshow' => false,
'animationSpeed' => 500,
'animationLoop' => false, // Breaks photoswipe pagination if true.
) ),
'zoom_enabled' => apply_filters( 'woocommerce_single_product_zoom_enabled', get_theme_support( 'wc-product-gallery-zoom' ) ),
'photoswipe_enabled' => apply_filters( 'woocommerce_single_product_photoswipe_enabled', get_theme_support( 'wc-product-gallery-lightbox' ) ),
'photoswipe_options' => apply_filters( 'woocommerce_single_product_photoswipe_options', array(
'shareEl' => false,
'closeOnScroll' => false,
'history' => false,
'hideAnimationDuration' => 0,
'showAnimationDuration' => 0
) ),
'flexslider_enabled' => apply_filters( 'woocommerce_single_product_flexslider_enabled', get_theme_support( 'wc-product-gallery-slider' ) ),
);
break;
}
return false;
}
For my product slider, I need to show prev and next arrows on single product page. So I need to change 'directionNav' as true.
How do I do this without making changes to the core files?
Have you created a child theme yet? If not, that's your first step. Here's a link from the WordPress codex:
https://codex.wordpress.org/Child_Themes
Then instead of editing that core file, you hook into that function instead, and write that code inside of the functions.php file you created in your child theme. If you want to add code to the existing function, you'll want to use an action hook. If you want to modify the code, you use a filter. It looks like you're trying to change the code, so probably a filter is best.
Here's how it would look using a filter:
add_filter( 'get_script_data', 'change_nav_direction' );
function change_nav_direction( $variable ) {
//any other code you may need
'directionNav' => true,
//you must have a return
return $variable;
}
Here's a link to an article from WooCommerce that might help:
https://docs.woocommerce.com/document/introduction-to-hooks-actions-and-filters/
I'm using the wp_get_archives function in Wordpress.
<?php $args = array(
'type' => 'monthly',
'limit' => '',
'format' => 'html',
'before' => '',
'after' => '',
'show_post_count' => false,
'echo' => 1,
'order' => 'DESC'
); ?>
<?php wp_get_archives( $args ); ?>
But I want to be able to change the URL - rather than it going to my Wordpress installation directory, how can I change it to my own custom URL?
PS: I found on the general-template.php file starting at line 937 is where this function starts.
I saw that, inside the function wp_get_archives, the links are built with the function get_archives_link(). There, we find the filter hook get_archives_link that returns each HTML link for the archives.
So, we can manipulate each of this strings and replace stuff:
add_filter( 'get_archives_link', function( $html )
{
if( is_admin() ) // Just in case, don't run on admin side
return $html;
// $html is '<li><a href='http://example.com/hello-world'>Hello world!</a></li>'
$html = str_replace( 'href="http://example.com', 'href="http://example.org', $html );
return $html;
});
brasofilo's solution worked for me, with some minor adjustments.
before:
$html = str_replace( 'href="http://example.com', 'href="http://example.org', $html );
after:
$html = str_replace( 'http://example.com', 'http://example.com/the_events', $html );