I have added a new section in customize section
function select_theme_stylesheet( $wp_customize ){
$wp_customize->add_section( 'theme_stylesheet_selector', array(
'title' => 'Select Color',
'priorty' => 50
));
$wp_customize->add_setting( 'theme_stylesheet_settings', array(
'default' => 'green',
'transport' => 'postMessage'
));
$wp_customize->add_control( new WP_Customize_Control( $wp_customize,'theme_stylesheet_control',array(
'type' => 'radio',
'label' => 'Theme Scheme',
'section' => 'theme_stylesheet_selector',
'settings' => 'theme_stylesheet_settings',
'choices' => array(
'green',
'blue'
),
'selection' => 'colors',
'priorty' => 9
) ));
}
add_action('customize_register', 'select_theme_stylesheet');
And I have the following function in 'customize.preview.js'
wp.customize( 'theme_stylesheet_control', function( value ) {
value.bind( function( newval ) {
alert("hello" + newval);
} );
} );
BUT It's not triggering. Can anyone please tell me what I'm missing.
Related
Hi guys i have created the custom post and custom texonomy for that custom post type but dont know why the texonomy not showing under admin menu bar please look into the code .veirfy is my custom post type .
function pluginprefix_setup_post_taxonomy()
{
define( 'TLC_PLUGIN_PATH', plugin_dir_url( __FILE__ ) );
define( 'TLC_PLUGIN_FULL_PATH', plugin_dir_path( __FILE__ ) );
// PCI DSS certificates
$labels_taxonomy = array(
'name' => 'Lead Assessors',
'singular_name' => 'Lead Assessor',
'menu_name' => 'Lead Assessor',
'all_items' => 'All Lead Assessors',
'parent_item' => 'Parent type',
'view_item' => 'View Lead Assessor',
'add_new_item' => 'Add Lead Assessor',
'add_new' => 'Add New Lead Assessor',
'show_in_menu' => 'Lead Assessor',
'edit_item' => 'Edit Lead Assessor',
'update_item' => 'Update Lead Assessor',
'search_items' => 'Search Lead Assessor',
'not_found' => 'Lead Assessors',
'not_found_in_trash' => 'Not found in Trash',
);
$args_taxonomy = array(
'hierarchical'=>true,
'labels' => $labels_taxonomy,
'query_var' => true,
'show_ui' => true,
// 'show_admin_column' => true,
'public' => true,
'show_in_nav_menus' => true,
'rewrite' => array('slug' =>'lead_assessor'),
);
// Registering your Custom taxonomy Type
register_taxonomy( 'lead_assessor', 'verify', $args_taxonomy );
// added in v3.0
flush_rewrite_rules();
}
add_action( 'init', 'pluginprefix_setup_post_taxonomy' );
I think your post type name and taxonomy name is same, so please check.
Or
You can use below code to create post type and taxonomy.
/**
* Register a custom post type called "LA Posts".
*
* #see get_post_type_labels() for label keys.
*/
function cptui_register_my_cpts() {
/**
* Post Type: LA Posts.
*/
$labels = array(
"name" => __( "LA Posts" ),
"singular_name" => __( "LA Post" ),
);
$args = array(
"label" => __( "LA Posts" ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"delete_with_user" => false,
"show_in_rest" => true,
"rest_base" => "",
"rest_controller_class" => "WP_REST_Posts_Controller",
"has_archive" => true,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "la_posts", "with_front" => true ),
"query_var" => true,
"supports" => array( "title", "editor", "thumbnail", "excerpt" ),
);
register_post_type( "la_posts", $args );
}
add_action( 'init', 'cptui_register_my_cpts' );
function cptui_register_my_taxes() {
/**
* Taxonomy: Lead Assessors.
*/
$labels_taxonomy = array(
'name' => 'Lead Assessors',
'singular_name' => 'Lead Assessor',
'menu_name' => 'Lead Assessor',
'all_items' => 'All Lead Assessors',
'parent_item' => 'Parent type',
'view_item' => 'View Lead Assessor',
'add_new_item' => 'Add Lead Assessor',
'add_new' => 'Add New Lead Assessor',
'show_in_menu' => 'Lead Assessor',
'edit_item' => 'Edit Lead Assessor',
'update_item' => 'Update Lead Assessor',
'search_items' => 'Search Lead Assessor',
'not_found' => 'Lead Assessors',
'not_found_in_trash' => 'Not found in Trash',
);
$args_taxonomy = array(
'hierarchical' =>true,
'labels' => $labels_taxonomy,
'query_var' => true,
'show_ui' => true,
'public' => true,
'show_in_nav_menus' => true,
'rewrite' => array('slug' =>'lead_assessor'),
);
register_taxonomy( "lead_assessor", array( "la_posts" ), $args_taxonomy );
}
add_action( 'init', 'cptui_register_my_taxes' );
I'm implementing Wordpress (from scratch) in a custom design and I'm having some issues with the functions.php file.
I don't have any plugins added to my website that current hosted locally with MAMP.
There are three parts of the code: one to create custom size of thumbnails, another to fix a media library error and another to create 3 different sidebar widgets.
I added the first two sections (thumbnail + media library) and everything worked fine, but after adding the last part (sidebar) the media library doesn't work again. When deleting the sidebar code, the media library works again. So these three parts are interfering and canceling each other out somehow.
I'm pretty sure my mistake is of syntax... Here is the full code:
<?php
// Add custom size of thumbnails
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 150, true ); // default Post Thumbnail dimensions (cropped)
add_image_size( 'another-size', 600, 400 ); // Not Cropped (additional sizes) size doesn't matter because we're adding "full"
}
// Fixes Media Library error (without this it's not possible to add images or manage it – it just appears empty)
function ms_image_editor_default_to_gd( $editors ) {
$gd_editor = 'WP_Image_Editor_GD';
$editors = array_diff( $editors, array( $gd_editor ) );
array_unshift( $editors, $gd_editor );
return $editors;
}
add_filter( 'wp_image_editors', 'ms_image_editor_default_to_gd' );
?>
<?php
// Created three different sidebars and allows user to edit their content as widgets
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'column 1',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => 'column 2',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => 'column 3',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
}?>
Try this, maybe you should use only one <?php ?> section
<?php
// Add custom size of thumbnails
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 150, true ); // default Post Thumbnail dimensions (cropped)
add_image_size( 'another-size', 600, 400 ); // Not Cropped (additional sizes) size doesn't matter because we're adding "full"
}
// Fixes Media Library error (without this it's not possible to add images or manage it – it just appears empty)
function ms_image_editor_default_to_gd( $editors ) {
$gd_editor = 'WP_Image_Editor_GD';
$editors = array_diff( $editors, array( $gd_editor ) );
array_unshift( $editors, $gd_editor );
return $editors;
}
add_filter( 'wp_image_editors', 'ms_image_editor_default_to_gd' );
// Created three different sidebars and allows user to edit their content as widgets
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'column 1',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => 'column 2',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => 'column 3',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
}?>
I'm trying to add a checkbox to the Customizer to "Display Background Image". When unchecked, it should set background-image: none to that element. I can't see where I'm going wrong.
This is what I have in my customizer.php file
// Background Image
$wp_customize->add_setting( 'background_image', array(
'default' => get_template_directory_uri() . '/images/default.jpg',
'transport' => 'postMessage'
) );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'background_image', array(
'label' => __( 'Background Image', 'minitheme' ),
'settings' => 'background_image'
) ) );
// Display Background Image
$wp_customize->add_setting( 'display_background_image', array(
'default' => true,
'transport' => 'postMessage'
) );
$wp_customize->add_control( 'display_background_image', array(
'label' => __( 'Display Background Image', 'minitheme' ),
'type' => 'checkbox'
) );
...
public static function header_output() {
?>
<!--Customizer CSS-->
<style type="text/css">
<?php self::generate_css( '#header', 'background-image', 'slide_1_background_image' ); ?>
#slide-1 {display: <?php
$display = get_theme_mod('display_slide_1_background_image', '1');
if ('false') {echo 'none';}
?>; }
</style>
<!--/Customizer CSS-->
<?php
}
THis is the code I have in my corresponding customizer.js file:
// Background Image
wp.customize( 'background_image', function( value ) {
value.bind( function( newval ) {
$('#slide-1').css('background-image', 'url("' + newval + '")' );
} );
} );
// Display Background Image
wp.customize( 'display_background_image', function( value ) {
value.bind( function( to ) {
if ( false === to ) {
$( '#header' ).css('background-image', 'none' );
}
});
});
Try removing the default value from 'background_image' setting.
I have a input like this on my first page <input type="number" id="people" name="ppl" min="1" class="uniform-input number" value="7" required="">
I wanted to use the value to toggle some fields on the woocommerce checkout. I want to show 2 name fields when the input value="2" and so on. But the code deletes all the custom fields. I don't know if I classed and targeted the div correctly Does anyone know what the problem is?
header.php
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function () {
toggleFields();
$("#people").on("keyup change", function () {
toggleFields();
});
});
function toggleFields() {
$("#personen1, #personen2, #personen3, #personen4, #personen5, #personen6, #personen7, #personen8").hide();
if ($("#people").val() < 9)
$("#personen" + $("#people").val()).show();
}
</script>
functions.php
function wordimpress_custom_checkout_field( $checkout ) {
//Check if Book in Cart (UPDATE WITH YOUR PRODUCT ID)
$book_in_cart = wordimpress_is_conditional_product_in_cart( 759 );
//Book is in cart so show additional fields
if ( $book_in_cart === true ) {
echo '<div class="container" id="personen1"><div class="jumbotron"><h2 style="color:red;">' . __( 'Buchungsinformationen' ) . '</h2>';
woocommerce_form_field( 'person1_name', array(
'type' => 'text',
'class' => array( 'person1 form-row-wide' ),
'placeholder' => 'Vorname und Nachname eingeben',
'label' => __( '1. Person' ),
), $checkout->get_value( 'person1_name' ) );
echo '</div>';
echo '<div class="container" id="personen2"><div class="jumbotron">';
woocommerce_form_field( 'person1_name', array(
'type' => 'text',
'class' => array( 'person1 form-row-wide' ),
'placeholder' => 'Vorname und Nachname eingeben',
'label' => __( '1. Person' ),
), $checkout->get_value( 'person1_name' ) );
woocommerce_form_field( 'person2_name', array(
'type' => 'text',
'class' => array( 'person2 form-row-wide' ),
'placeholder' => 'Vorname und Nachname eingeben',
'label' => __( '2. Person' ),
), $checkout->get_value( 'person2_name' ) );
echo '</div>';
}
}
I created a custom post type and also a custom taxonomy for that post type. Everything seems to be working... except when I go to create a new post, if I click on "+ Add New Category" it changes the URL, but nothing happens. All the other JS buttons work and it works just fine on regular posts.. not sure why it is doing this. Below is the codes i am using the the functions.php file.
Register Custom Post Type
/* Custom Post Type Galleries */
function bhgallery_register_post_type() {
$singular = 'Gallery';
$plural = 'Galleries';
$labels = array (
'name' => $plural,
'singular' => $singular,
'add_name' => 'Create New',
'add_new_item' => 'Create New ' . $singular,
'edit' => 'Edit',
'edit_item' => 'Edit ' . $singular,
'new_item' => 'New' . $singular,
'view' => 'View' . $singular,
'view_item' => 'View' . $singular,
'search_term' => 'Search ' . $plural,
'parent' => 'Parent ' . $singular,
'not_found' => 'No ' . $plural . ' Found',
'not_found_in_trash' => 'No ' . $plural . ' in Trash'
);
$args = array (
'labels' => $labels,
'public' => true,
'public_queryable' => true,
'exclude_from_search' => false,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 10,
'menu_icon' => 'dashicons-camera',
'can_export' => true,
'delete_with_user' => false,
'hierarchical' => false,
'has_archive' => true,
'query_var' => true,
'capability_type' => 'post',
'map_meta_cap' => true,
// 'capabilities' => array();
'rewrite' => array(
'slug' => 'gallery',
'with_front' => true,
'pages' => true,
'feeds' => false,
),
'supports' => array(
'title',
'thumbnail',
'editor'
)
);
register_post_type( 'bh_gallery', $args );
}
add_action ( 'init', 'bhgallery_register_post_type');
CUSTOM TAXONOMY
/** Custom Categories for Gallery **/
function bhgallery_register_taxonomy() {
$plural = 'Categories';
$singular = 'Category';
$labels = array (
'name' => $plural,
'singular_name' => $singular,
'search_items' => 'Search ' . $plural,
'popular_items' => 'Popular ' . $plural,
'all_items' => 'All ' . $plural,
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => 'Edit ' . $singular,
'update_item' => 'Update ' . $singular,
'add_new_item' => 'Add New ' . $singular,
'new_item_name' => 'New ' . $singular . ' Name',
'separate_items_with_comas' => 'Seperate ' . $singular . ' with commas',
'add_or_remove_items' => 'Add or remove ' . $plural,
'choose_from_most_used' => 'Choose from the most used ' . $plural,
'not_found' => 'No ' . $plural . 'fount',
'menu_name' => $plural,
);
$args = array (
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'categories'),
);
register_taxonomy( 'gallery category', 'bh_gallery', $args );
}
add_action ( 'init', 'bhgallery_register_taxonomy');
If there is anything else you need to know, let me know.
Your second to last line of code above has
register_taxonomy( 'gallery category', 'bh_gallery', $args );
From the codex, register taxonomy, the first argument should not have any spaces. In fact, there are very few places that spaces are ever allowed and they are mainly limited to strings meant for display.
$taxonomy (string) (required) The name of the taxonomy. Name should
only contain lowercase letters and the underscore character, and not
be more than 32 characters long (database structure restriction).