Here is the code added to theme function.php file
function my_theme_add_screen_options() {
print("FukjndfrkevnkerdsjfvgkrjedvfgkFukjndfrkevnkerdsjfvgkrjedvfgkFukjndfrkevnkerdsjfvgkrjedvfgkFukjndfrkevnkerdsjfvgkrjedvfgkFukjndfrkevnkerdsjfvgkrjedvfgk");
add_screen_option(
'trbhnr_thbgrb',
array(
'label' => __( 'My Theme New Option' ),
'default' => true,
)
);
}
add_action( 'load-post.php', 'my_theme_add_screen_options' );
Now this does print the test text in print when editing posts wp-admin/post.php?post=1&action=edit&classic-editor but the option isn't included and there are no errors in the log
Related
Need a solution to remove the "Title" and "Add new" button from a post type without jQuery.
You can disable the add new capabilities while passing the parameter in the register post type.
The parameter is :
create_posts' => false
Assuming you have the code like below :
$args = array(
'label' => __( 'Custom Post Type', 'text_domain' ),
'capabilities' => array(
'create_posts' => false
)
);
register_post_type( 'custom_post_type', $args );
In order to remove the title I'm not sure if that is possible,
one solutions would be hiding using css
Best way to remove the title is to use the function remove_post_type_support().
remove_post_type_support('custom_post_type', 'title');
You can add this to your functions.php file by calling it via the init hook.
add_action( 'init', 'remove_custom_post_support' );
function remove_custom_post_support() {
remove_post_type_support( 'custom_post_type', 'title' );
}
I'm building custom tinymce bar buttons for my wp theme, using wp_editor and teeny, but I have a problem. When I add hr and charmap, these buttons not appear in the tinymce bar.
This is the wp_editor configuration:
$settings = array(
'textarea_name' => 'xor_options[' . $editor . ']',
'quicktags' => array( 'buttons' => 'strong,em,del,ul,ol,li,close' ),
'media_buttons' => true,
'wpautop' => false,
'textarea_rows' => 5,
'editor_height' => 200,
'teeny' => true,
'tinymce' => true
);
wp_editor( $xor_output, $xor_editor_id, $settings );
Now I'm using the filter for teeny buttons.
add_filter( 'teeny_mce_buttons', 'xor_editor_buttons', 10, 2 );
function xor_editor_buttons( $buttons, $editor_id ) {
if( $editor_id != 'footer-editor' ) return $buttons;
$buttons = array(
'undo',
'redo',
'formatselect',
'bold',
'italic',
'underline',
'strikethrough',
'blockquote',
'bullist',
'numlist',
'outdent',
'indent',
'alignleft',
'alignright',
'aligncenter',
'alignjustify',
'link',
'unlink',
'hr', // not appears!
'charmap', // not appears!
'removeformat',
'fullscreen'
);
return $buttons;
}
Where is the error in my code or this is a little bug? I'm using Wordpress 4.9. Thanks!
SOLVED
I set on false teeny. Then I set tinymce as array:
'tinymce' => array(
'toolbar1' => $b,
'toolbar2' => '',
'toolbar3' => '',
)
Where $b is all buttons that I need (included hr and charmap). See:
Wordpress Developers
Before you can load the toolbar buttons you need to load the plugins:
https://www.tinymce.com/docs/plugins/hr/
https://www.tinymce.com/docs/plugins/charmap/
You first need to see if the TinyMCE embedded in your WP version includes these plugins (they are in a standard WordPress setup). You then need to add these plugins to the list of loaded plugins. Once they are loaded adding the buttons to the toolbar will work.
I don't know anything about teenymce but (as an example) this is how TinyMCE Advanced loads extra plugins via a WordPress hook:
add_filter( 'tiny_mce_plugins', array( $this, 'tiny_mce_plugins' ), 999 );
(The array is a list of plugin folder names)
I wanted to make custom WordPress theme from scratch so i deleted all my themes, and now the Menu is missing from appearance bar,
i tried adding add_theme_support( 'menus' ); code in functions.php file then my page itself is not opening.
Attached is the screenshot for your reference.
pls help
You need to registered menu using register_nav_menus() in after_setup_theme action hook.
Please check below code. it help you to create two type of menu display location
function custom_theme_setup() {
register_nav_menus( array(
'primary' => esc_html__( 'Primary Menu', 'nepalbuzz' ),
'footer' => esc_html__( 'Footer Menu', 'nepalbuzz' ),
) );
}
add_action( 'after_setup_theme', 'custom_theme_setup' );
This code goes to your custom theme function.php file
For display menu used wp_nav_menu() function.
if ( has_nav_menu( 'primary' ) ) {
$args = array(
'theme_location' => 'primary',
'menu_class' => 'menu nepalbuzz-nav-menu',
'container' => false
);
wp_nav_menu( $args );
}
This code goes to your custom theme file where you want to display menu
Use this in your functions.php
register_nav_menus(
array('header_menu' =>'This is Header Menu'));
to display this menu use this code where you want to display your menu
wp_nav_menu(array('theme_location'=>'header_menu','container'=>''));
Please use register_nav_menus()
So that you can create a custom Menu for your theme. Like
function register_theme_menu() {
register_nav_menu( 'primary', __( 'Primary Menu', 'theme-slug' ) );
}
After that add the menu by "after_setup_theme" hook like
add_action( 'after_setup_theme', 'register_theme_menu' );
The full code is like in you fuctions.php file.
add_action( 'after_setup_theme', 'register_theme_menu' );
function register_theme_menu() {
register_nav_menu( 'primary', __( 'Primary Menu', 'theme-slug' ) );
}
get full info from https://codex.wordpress.org/Function_Reference/register_nav_menu
I have an Ajax checkout on my woocommerce installation and I am trying to capture the custom fields on the checkout. I am using below code to try to capture the field called add_gift_box, the field appears fine on my checkout page.
add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta' );
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ($_POST['add_gift_box']) {
update_post_meta( $order_id, '_add_gift_box', esc_attr($_POST['add_gift_box']));
}
}
When I press "place order" button it creates a new order but the value of this field does not get saved in the database. I don't think even the hook gets fired. As I said everything is being handled by Ajax. The checkout page is one page checkout.
I need help sorting this out. Thanks in advance.
UPDATE
I am setting the field as follows:
add_action( 'woocommerce_after_checkout_billing_form', 'add_box_option_to_checkout' );
function add_box_option_to_checkout( $checkout ) {
woocommerce_form_field( 'add_gift_box', array(
'type' => 'radio',
'class' => array('add_gift_box form-row-wide'),
'label_class' => array('checkbox'),
'input_class' => array('input-checkbox'),
'required' => true,
'options' => array(
'option_1' => 'option1</br>' ,
'option_2' =>'option2</br>',
'option_3' =>'option3</br>',
'option_4' =>'option4</br>',
'option_5' =>'option5</br>',
'option_6' =>'option6</br>',
'option_7' =>'option7</br>',
),
'label' => __('Select Option'),
'placeholder' => __(''),
), $checkout->get_value( 'add_gift_box' ));
}
here is a plugin to add custom field on checkout page woocomerce https://wordpress.org/plugins/woo-custom-checkout-field/
or if you want to add by code you can follow codding from here
https://www.cloudways.com/blog/custom-field-woocommerce-checkout-page/
add_action('woocommerce_after_order_notes', 'customise_checkout_field');
function customise_checkout_field($checkout)
{
echo '<div id="customise_checkout_field"><h2>' . __('Heading') . '</h2>';
woocommerce_form_field('customised_field_name', array(
'type' => 'text',
'class' => array(
'my-field-class form-row-wide'
) ,
'label' => __('Customise Additional Field') ,
'placeholder' => __('Guidence') ,
'required' => true,
) , $checkout->get_value('customised_field_name'));
echo '</div>';
}
Do you have a plugin activated which creates the order by hooking into woocommerce_create_order filter? I don't see any other reason why add_gift_box isn't saved or why woocommerce_checkout_update_order_meta isn't firing.
The original code from includes/class-wc-checkout.php is
/**
* Action hook to adjust order before save.
* #since 3.0.0
*/
do_action( 'woocommerce_checkout_create_order', $order, $data );
// Save the order.
$order_id = $order->save();
do_action( 'woocommerce_checkout_update_order_meta', $order_id, $data );
So, you could create log files in your themes directory to see which hooks are firing like this:
add_action('woocommerce_checkout_update_order_meta', function ($order_id) {
file_put_contents(__DIR__ . '/woocommerce_checkout_update_order_meta.log', 'woocommerce_checkout_update_order_meta fired for order id ' . $order_id);
});
add_action('woocommerce_checkout_create_order', function () {
file_put_contents(__DIR__ . '/woocommerce_checkout_create_order.log', 'woocommerce_checkout_create_order fired');
});
I am working on a WordPress site. While adding some widget in widget section, I got some issue.
I add some thing in primary widget area and right widget area, and when I refresh the widget page my added content got disappear although it is displaying in the front-end of WordPress,but now I am not able to edit that content from admin section.
My code is as follows:
add_filter( 'sidebars_widgets', 'disable_sidebar_L_widgets' );
function disable_sidebar_L_widgets( $sidebars_widgets ) {
if (!is_front_page() ) $sidebars_widgets['primary-widget-area'] = false;
return $sidebars_widgets; }
add_filter( 'sidebars_widgets', 'disable_sidebar_R_widgets' );
function disable_sidebar_R_widgets( $sidebars_widgets ) {
if (!is_front_page() ) $sidebars_widgets['right-widget-area'] = false;
return $sidebars_widgets;
}
Edit functions.php and locate for register_sidebar function. Change the id to small caps example :
register_sidebar( array(
'name' => __( 'Main Sidebar', ),
'id' => 'sidebar-1',
'before_widget' => '',
'after_widget' => "",
'before_title' => '',
'after_title' => '',
) );