How to delete Widget Areas in Wordpress - wordpress

I am using WordPress to create a site for an estate agency.
I would like to have a minimal homepage, with a text area and a background image. In the theme I am using (Agent Press) every page has 2 widget areas that I would like to delete. Is there a way to do it? I don't mind using any plugin or modifying code too. Thank you for your time and consideration.
Edit: this is my sidebar.php in the "father" theme called Genesis, where should I put the code you suggested me? (I don't know if it is right to edit this file)
<?php
/**
* Genesis Framework.
*
* WARNING: This file is part of the core Genesis Framework. DO NOT edit this
file under any circumstances.
* Please do all modifications in the form of a child theme.
*
* #package Genesis\Templates
* #author StudioPress
* #license GPL-2.0+
* #link http://my.studiopress.com/themes/genesis/
*/
//* Output primary sidebar structure
genesis_markup( array(
'html5' => '<aside %s>' . genesis_sidebar_title( 'sidebar' ),
'xhtml' => '<div id="sidebar" class="sidebar widget-area">',
'context' => 'sidebar-primary',
) );
do_action( 'genesis_before_sidebar_widget_area' );
do_action( 'genesis_sidebar' );
do_action( 'genesis_after_sidebar_widget_area' );
genesis_markup( array(
'html5' => '</aside>', //* end .sidebar-primary
'xhtml' => '</div>', //* end #sidebar
) );
Edit: Here you are the screenshot of the pages you want to know about, tell me which you want to know more about.
Edit: front-page.php
<?php
/**
* This file adds the Home Page to the AgentPress Pro Theme.
*
* #author StudioPress
* #package AgentPress Pro
* #subpackage Customizations
*/
//* Enqueue scripts
add_action( 'wp_enqueue_scripts', 'agentpress_front_page_enqueue_scripts'
);
function agentpress_front_page_enqueue_scripts() {
//* Load scripts only if custom background is being used
if ( ! get_option( 'agentpress-home-image' ) )
return;
//* Enqueue Backstretch scripts
wp_enqueue_script( 'agentpress-backstretch', get_bloginfo( 'stylesheet_directory' ) . '/js/backstretch.js', array( 'jquery' ), '1.0.0' );
wp_enqueue_script( 'agentpress-backstretch-set', get_bloginfo( 'stylesheet_directory' ).'/js/backstretch-set.js' , array( 'jquery', 'agentpress-backstretch' ), '1.0.0' );
wp_localize_script( 'agentpress-backstretch-set', 'BackStretchImg', array( 'src' => str_replace( 'http:', '', get_option( 'agentpress-home-image' ) ) ) );
//* Add agentpress-pro-home body class
add_filter( 'body_class', 'agentpress_body_class' );
}
add_action( 'genesis_meta', 'agentpress_home_genesis_meta' );
/**
* Add widget support for homepage. If no widgets active, display the default loop.
*
*/
function agentpress_home_genesis_meta() {
if ( is_active_sidebar( 'home-featured' ) || is_active_sidebar( 'home-top' ) || is_active_sidebar( 'home-middle-1' ) || is_active_sidebar( 'home-middle-2' ) || is_active_sidebar( 'home-middle-3' ) || is_active_sidebar( 'home-bottom' ) ) {
//* Force full-width-content layout setting
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
//* Remove breadcrumbs
remove_action( 'genesis_before_content_sidebar_wrap', 'genesis_do_breadcrumbs' );
//* Remove the default Genesis loop
remove_action( 'genesis_loop', 'genesis_do_loop' );
//* Add home featured area
add_action( 'genesis_after_header', 'agentpress_home_featured_widget' );
//* Add home widget area
add_action( 'genesis_before_footer', 'agentpress_home_widgets', 1 );
}
}
function agentpress_body_class( $classes ) {
$classes[] = 'agentpress-pro-home';
return $classes;
}
function agentpress_home_featured_widget() {
genesis_widget_area( 'home-featured', array(
'before' => '<div class="home-featured full-width widget-area"><div class="wrap">',
'after' => '</div></div>',
) );
}
function agentpress_home_widgets() {
/*genesis_widget_area( 'home-top', array(
'before' => '<div class="home-top full-width widget-area"><div class="wrap">',
'after' => '</div></div>',
) ); */
if ( is_active_sidebar( 'home-middle-1' ) || is_active_sidebar( 'home-middle-2' ) || is_active_sidebar( 'home-middle-3' ) ) {
echo '<div class="home-middle"><div class="wrap">';
genesis_widget_area( 'home-middle-1', array(
'before' => '<div class="home-middle-1 full-width widget-area">',
'after' => '</div>',
) );
genesis_widget_area( 'home-middle-2', array(
'before' => '<div class="home-middle-2 widget-area">',
'after' => '</div>',
) );
genesis_widget_area( 'home-middle-3', array(
'before' => '<div class="home-middle-3 widget-area">',
'after' => '</div>',
) );
echo '</div></div>';
}
genesis_widget_area( 'home-bottom', array(
'before' => '<div class="home-bottom full-width widget-area"><div class="wrap">',
'after' => '</div></div>',
) );
}
genesis();`

You need to set an if statement on your sidebar code. use the is_page() function of wordpress:
if( ! is_page('home') ){ // Remove the sidebar on home page
dynamic_sidebar('your-sidebar-id');
}
You can also set your sidebar on a specific page via ID or slug.
if( is_page( 123 ) ){ // via ID
dynamic_sidebar('your-sidebar-id-1'); // Sidebar 1
}elseif( is_page('contact-us') ){ // via slug
dynamic_sidebar('your-sidebar-id-2'); // Sidebar 2
}

Edited:
Navigate to Appearance > Editor on the left in the Wordpress
Dashboard.
On the Edit Themes page, select the sidbar.php page on the right
hand side in the Templates section.
The code for the sidebar.php will load in the Theme editor window.
Add a comment to the code like in the snapshot to the right. HTML
comments look like the following:
<!-- Begin Comment
Code goes in between here
End Comment -->
Add the comment code to the page in the Theme editor and Click Update File

Related

Media contents, Woocommerce Login Forms becomes unavailable when a certain line of code is included in functions.php

Happy to be here and elated to have interactions with you.
I have a challenge I need help with to determine the causative issue. I am creating a wordpress theme for a woocommerce store, as a first timer. All is going well, although challenging and tasking (I like it like that).
In the cause of the development, I observed that I could not access the media folder or the login section of the theme when put oline (accessed on liveserver), but on the local development server all works fine.
After much troubleshooting by checking all codes in the different file, by excluding and including diffrent lines of codes, I discovered the trigger is coming from a section of the functions.php file. Find below the codes therein, with the pain-point highlighted at 7.2. :
<?php
/**
*
* +++++++++++++++++++++++++++++++++++++++++++++++++++
* + THEME FUNCTIONS & WIDGETS +
* +++++++++++++++++++++++++++++++++++++++++++++++++++
*
* */
/********************************************************************************************
* 1.0. REGISTER STYLESHEETS AND SCRIPTS **********************************************************************************************/
// 1.1. register and enqueue stylesheets
function load_stylesheets()
{
if(!is_admin()){
wp_register_style('stylesheet', get_template_directory_uri() . '/style.css', '', 1, 'all');
wp_enqueue_style('stylesheet');
wp_register_style('custom', get_template_directory_uri() . '/assets/css/app.css?asasggfghf=asfsfrrdfghghfgdgsdg', '', 1, 'all');
wp_enqueue_style('custom');
wp_register_style('woostyles', get_template_directory_uri() . '/assets/css/woocommerce/woocommerce.css?asdadsfggdgfdfd=fgfghghgjjhj', '', 1, 'all');
wp_enqueue_style('woostyles');
wp_register_style('woolayout', get_template_directory_uri() . '/assets/css/woocommerce/woocommerce-layout.css?asfdffgd=sdsfggf', '', 1, 'all');
wp_enqueue_style('woolayout');
wp_register_style('fontawesome', get_template_directory_uri() . '/assets/fontawesome/css/all.min.css', '', 1, 'all');
wp_enqueue_style('fontawesome');
}
}
add_action('wp_enqueue_scripts', 'load_stylesheets');
// 1.2. register and enqueue javascripts
function load_javascript()
{
if(!is_admin()){
wp_enqueue_script('jquery');
wp_register_script('custom', get_template_directory_uri() . '/assets/js/app.js?adddghhjkjk', 'jQuery', 1, true);
wp_enqueue_script('custom');
wp_register_script('form-validate', get_template_directory_uri() . '/assets/js/jquery.validate.min.js', 'jQuery', 1, true);
wp_enqueue_script('form-validate');
}
}
add_action('wp_enqueue_scripts', 'load_javascript');
/********************************************************************************************
* 2.0. THEME'S SITE AND CUSTOMISATIONS **********************************************************************************************/
//2.1. Activates Support for Theme's Custom Logo Setup
function config_theme_custom_logo(){
// Custom image size created somewhere in your code.
add_image_size( 'custom-image-size' , '' , '' , true );
$defaults = array(
'height' => 'custom-image-size',
'width' => 'custom-image-size',
'flex-height' => true,
'flex-width' => true,
'class' => 'logo',
'header-text' => array( 'site-title', 'site-description' ),
'unlink-homepage-logo' => false,
);
add_theme_support( 'custom-logo', $defaults );
}
add_action( 'after_setup_theme' , 'config_theme_custom_logo' );
//2.2. Activate Support for Theme's Site Logo and Name Customization Setup
function theme_site_logo(){
if ( has_custom_logo() ) {
$logo = wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ) , 'full' );
echo '<a class="site-logo-link" href="' . get_site_url() . '" >';
echo '<img class="img-fluid logo" src="' . esc_url( $logo[0] ) . '" width="' . $logo[1] . '" height="' . $logo[2] . '" alt="' . get_bloginfo( 'name' ) . '">';
echo "</a>";
}
else {
echo '<a href="' . get_site_url() . '" class="site-name-link" >';
echo '<h2>' . get_bloginfo( 'name' ) . '</h2>';
echo '</a>';
echo '<span class="site-description" >' . get_bloginfo( 'description' ) . '</span>';
}
}
/********************************************************************************************
* 3.0. ACTIVATES THEME'S WORDPRESS SUPPORT FEATURES MORE **********************************************************************************************/
function themes_support_features()
{
// 3.1. Activates Supports for Custom Menu
add_theme_support('menus');
// 3.1.1. Register's Location for 4 Navigation Menus
$locations = array(
'primary' => __( 'Primary Menu', 'devtheme' ),
'expanded' => __( 'Expanded Menu', 'devtheme' ),
'mobile' => __( 'Mobile Menu', 'devtheme' ),
'footer' => __( 'Footer Menu', 'devtheme' ),
'social' => __( 'Social Menu', 'devtheme' ),
);
// 3.1.2. Register's Location for 4 Navigation Menus
register_nav_menus( $locations );
//3.2. HTML5 Search: activate Theme's search form
add_theme_support('html5', array('search-form'));
//3.3. HTML5 Search: activate Theme's search form
add_theme_support('post-thumbnails');
}
add_action('init', 'themes_support_features');
/********************************************************************************************
* 4.0. LOAD THEME'S CUSTOM FUNCTIONS AND MORE **********************************************************************************************/
//4. Activate theme's support for Walker Class
require get_template_directory() . '/inc/walkerClasschild.php';
require get_template_directory() . '/inc/adhoc-functions.php';
/********************************************************************************************
* 5.0. LOAD THEME'S WIDGETS AND MORE **********************************************************************************************/
//** 5.1. */
require_once get_template_directory() . '/lib/theme-widgets.php';
require get_template_directory() . '/inc/allowSVG.php';
//* 5.2. Change Footer Widget Menu Properties
function custom_nav_args( $args ) {
return array_merge( $args, array(
'container_class' => 'widget-content',
'menu_class' => '',
'walker' => '',
// another setting go here ...
) );
}
add_filter( 'widget_nav_menu_args', 'custom_nav_args' );
/****************************************************************
* 8.0. Support using shortcodes in Widgets *
****************************************************************/
add_filter( 'widget_text', 'shortcode_unautop' );
add_filter( 'widget_text', 'do_shortcode' );
/********************************************************************************************
* 6.0. ACTIVATES THEME'S WORDPRESS CUSTOMIZER FEATURES & MORE **********************************************************************************************/
/**
* Do not include twice the file below.
*/
if ( file_exists( get_template_directory() . '/inc/api-customizer.php' ) ) {
require get_template_directory() . '/inc/api-customizer.php';
}
/********************************************************************************************
* 7.0. ACTIVATES WOOCOMMERCE & FEATURES TO THE THEME * ********************************************************************************************/
//**7.1. Theme Support for WooCommerce */
//**7.1.1. Adds constant that returns true if Woocommerce is Active */
define( 'WPEX_WOOCOMMERCE_ACTIVE', class_exists( 'WooCommerce' ) );
//**7.1.2. Check if Woocommerce is Active */
if ( WPEX_WOOCOMMERCE_ACTIVE ){
add_action('after_setup_theme', function(){
add_theme_support('woocommerce');
});
}
**
//** 7.2. WooCommerce Hooks */
if (class_exists('WooCommerce') && file_exists( get_template_directory() . '/inc/woocommerce-hooks.php' ) ) {
require get_template_directory() . '/inc/woocommerce-hooks.php';
}
**
Once the code section 7.2. is added (i.e. code to link the file containing hooks for woocommerce plugin) the malfunction shows face, even when the file contains no codes. Once that section is taken out, everything then works fine.
Can anyone help to determine what it is I have included in top sections of the functions codes?

custom field value isn't stored in variation_data object

i have following issue with woocommerce/dokan:
I created a custom field for product variation:
custom field in wordpress backend
It works fine, the values are storing and i can change the value at the backend. Therefor i added following lines of code into function.php of theme file:
function variation_settings_fields( $loop, $variation_data, $variation ) {
// Text Field
woocommerce_wp_text_input(
array(
'id' => '_text_field[' . $variation->ID . ']',
'label' => __( 'My Text Field', 'woocommerce' ),
'placeholder' => 'http://',
'desc_tip' => 'true',
'description' => __( 'Enter the custom value here.', 'woocommerce' ),
'value' => get_post_meta( $variation->ID, '_text_field', true )
)
);
}
/**
* Save new fields for variations
*
*/
function save_variation_settings_fields( $post_id ) {
// Text Field
$text_field = $_POST['_text_field'][ $post_id ];
if( ! empty( $text_field ) ) {
update_post_meta( $post_id, '_text_field', esc_attr( $text_field ) );
}
}
// Add New Variation Settings
add_filter( 'woocommerce_available_variation', 'load_variation_settings_fields' );
/**
* Add custom fields for variations
*
*/
function load_variation_settings_fields( $variations ) {
// duplicate the line for each field
$variations['text_field'] = get_post_meta( $variations[ 'variation_id' ], '_text_field', true );
return $variations;
}
So far, so good. I can set a value and the value can be saved over the backend.
Now i want to change the custom field for this product variation in dokan vendor dashboard. I duplicated html-product-variation.php file into child theme and added the new field:
dokan vendor dashboard product variation
with following code:
<div>
<p class="dokan-form-group">
<label><?php esc_html_e( 'Custom Textfield', 'dokan' ); ?></label>
<textarea class="dokan-form-control" name="_text_field[<?php echo esc_attr( $loop ); ?>]" rows="3" style="width:100%;"><?php echo isset( $variation_data['_text_field'] ) ? esc_textarea( $variation_data['_text_field'] ) : ''; ?></textarea>
</p>
</div>
The problem is, that the value, which i set in the backend isn't shown and if i inspect the variation_data object there is no key in the array which says "_text_field". How can i store/update variation_data object?
I hope it's understandable which issue i'm facing here and look forward to some help :)
Best wishes,
Florian

Media Modal Gutenberg missing styles

So today, all my websites were updated to the new release of WordPress 5.9.1. Good good. However, my custom blocks in Gutenberg that are containing an image element are breaking the style of the media modal (where you can add an image directly in the post).
I started a new project, just to test if it was my theme, or the plugins, but even without any plugin (except ACF Pro) and on the Twenty Twenty-Two theme, if I add my registration code in the functions.php file of 2022 theme, I get the same problem.
Here's the register-block code:
add_action('acf/init', 'my_acf_init_block_types');
function my_acf_init_block_types() {
if( function_exists('acf_register_block_type') ) {
acf_register_block_type(array(
'name' => 'carousel',
'title' => __('Carrousel'),
'description' => __(''),
'render_template' => 'web/blocks/carousel.php',
'category' => 'custom-blocks',
'icon' => 'images-alt',
'keywords' => array( 'carousel', 'carrousel'),
'supports' => array( 'anchor' => true),
));
}
}
And I've created a Field group trying the image with the array annnnnd the one using only the URL.
What I tried:
no plugins (except ACF)
WP theme (2022)
custom theme with no functions
adding the registration code to 2022 theme (same error)
Please, help a sister our here.
I think it was cause by the 5.9.1 update
You can use this in functions.php as temporary fix
function fix_media_views_css() {
echo '<link rel="stylesheet" id="fix-media-views-css" href="'.get_bloginfo('url').'/wp-includes/css/media-views.min.css?ver=5.9.1" media="all">';
}
add_action('admin_footer', 'fix_media_views_css');
I've added that piece of code to my functions.php file (at the end, no biggy).
function acf_filter_rest_api_preload_paths( $preload_paths ) {
if ( ! get_the_ID() ) {
return $preload_paths;
}
$remove_path = '/wp/v2/' . get_post_type() . 's/' . get_the_ID() . '?context=edit';
$v1 = array_filter(
$preload_paths,
function( $url ) use ( $remove_path ) {
return $url !== $remove_path;
}
);
$remove_path = '/wp/v2/' . get_post_type() . 's/' . get_the_ID() . '/autosaves?context=edit';
return array_filter(
$v1,
function( $url ) use ( $remove_path ) {
return $url !== $remove_path;
}
);
}
add_filter( 'block_editor_rest_api_preload_paths', 'acf_filter_rest_api_preload_paths', 10, 1 );
It works perfectly like before. I've tried to downversion it to 5.9 and it worked as well, but it takes more time/effort and many mistakes can happen.
Hope it helps more than one.
ACF is aware of the issue: https://github.com/AdvancedCustomFields/acf/issues/612
Here is the temp fix, paste in your functions.php:
function acf_filter_rest_api_preload_paths( $preload_paths ) {
global $post;
$rest_path = rest_get_route_for_post( $post );
$remove_paths = array(
add_query_arg( 'context', 'edit', $rest_path ),
sprintf( '%s/autosaves?context=edit', $rest_path ),
);
return array_filter(
$preload_paths,
function( $url ) use ( $remove_paths ) {
return ! in_array( $url, $remove_paths, true );
}
);
}
add_filter( 'block_editor_rest_api_preload_paths', 'acf_filter_rest_api_preload_paths', 10, 1 );

How can I change the position of quantity Field?

I have tried lots of hooks but did not able to change the position of quantity field in woo-commerce single product page. So please let me know how can I move quantity box above the 'color'. Please have a
look at screenshot for more details:
screenshot:-
https://prnt.sc/t9ri39
You can create a child theme and copy the file
woocommerce/templates/single-product/add-to-cart/variation-add-to-cart-button.php
to:
themes/your-child-theme/woocommerce/single-product/add-to-cart/variation-add-to-cart-button.php.
So basically the same file structure but without the templates folder. More information about templates here: WooCommerce template structure
After you've copied the file you can remove the quantity field from it by cutting out line 17 until 29:
<?php
do_action( 'woocommerce_before_add_to_cart_quantity' );
woocommerce_quantity_input(
array(
'min_value' => apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ),
'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ),
'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( wp_unslash( $_POST['quantity'] ) ) : $product->get_min_purchase_quantity(), // WPCS: CSRF ok, input var ok.
)
);
do_action( 'woocommerce_after_add_to_cart_quantity' );
?>
Then add the quantity field again before the variations form with a small code snippet:
add_action( 'woocommerce_before_variations_form', 'add_quantity_field_before_variations_form', 10 );
function add_quantity_field_before_variations_form() {
global $product;
do_action( 'woocommerce_before_add_to_cart_quantity' );
woocommerce_quantity_input(
array(
'min_value' => apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ),
'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ),
'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( wp_unslash( $_POST['quantity'] ) ) : $product->get_min_purchase_quantity(), // WPCS: CSRF ok, input var ok.
)
);
do_action( 'woocommerce_after_add_to_cart_quantity' );
}
Add this code snippet to the functions.php of your child theme.

connect woocommerce products to posts

I am using woocommerce on my wordpress site.
I am selling paintings. The products are paintings.
I have a list of artists as posts. Each artist is one post.
I would like to connect the posts and products so I can show the artist's name on the painting page and the user can click on the name and it takes them to the artist post.
How do I do this?
This is an example of how to add a custom field in WooCommerce product general tab. Since artists are posts ( category is not specified ), it will collect links for all posts and place them in a dropdown. The value of this field will be visible on the single product page below the price ( you can open the content-single-product.php file in WooCommerce theme, to see the actions for single product template, and functions attached, and change the priority of woocommerce_product_artist function if you want to change the place where the link will appear ).
<?php
add_action( 'admin_init', 'woocommerce_custom_admin_init' );
function woocommerce_custom_admin_init() {
// display fields
add_action( 'woocommerce_product_options_general_product_data', 'woocommerce_add_custom_general_fields' );
// save fields
add_action( 'woocommerce_process_product_meta', 'woocommerce_save_custom_general_fields' );
}
function woocommerce_add_custom_general_fields() {
// creating post array for the options ( id => title)
$posts = array( '' => __( 'Select Artist' ) );
array_walk( get_posts( array( 'numberposts' => -1 ) ), function( $item ) use ( &$posts ) {
$posts[ $item->ID ] = $item->post_title;
} );
// creating dropdown ( woocommerce will sanitize all values )
echo '<div class="options_group">';
woocommerce_wp_select(
array(
'id' => '_artist',
'label' => __( 'Artist' ),
'options' => $posts
)
);
echo '</div>';
}
function woocommerce_save_custom_general_fields( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
// validate id of artist page and save
if ( isset( $_POST['_artist'] ) ) {
$value = filter_input( INPUT_POST, '_artist', FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 0 ) ) );
update_post_meta( $post_id, '_artist', $value );
}
}
add_action( 'init', 'woocommerce_custom_init' );
function woocommerce_custom_init() {
// hook the woocommerce_product_artist function on to woocommerce_single_product_summary action ( priority 15 )
add_action( 'woocommerce_single_product_summary', 'woocommerce_product_artist', 15 );
}
function woocommerce_product_artist() {
global $post;
// get the artist page id and show in template ( if exists )
$artist_id = get_post_meta( $post->ID, '_artist', true );
if ( $artist_id ) :
?>
<div class="product-artist"><?php echo get_the_title( $artist_id ); ?></div>
<?php endif;
}
?>

Resources