WordPress widget area disapper - wordpress

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' => '',
) );

Related

add_screen_option Doesn't add option to the screen options panel

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

WordPress: Is it possible to add a widget to footer/sidebar on widget activation?

I have managed to follow fuxia's solution on adding a default widget to the footer sidebar but the widget doesnt seem to be "activated" (I have to remove and manually add it back to the footer sidebar for the widget to work, making the pre-set widget code pointless). I found that the widget added by the aforementioned solution and the same widget pulled from the list of available widgets are different. The picture below shows different href values for the widget items in the footer list of widgets. (Grey boxes are just the widget name)
I'm not sure if this is the reason behind the issue but is there a way to add the widget to the footer sidebar AND have it work/"activated"?
EDIT: current implementation
add_action( 'widgets_init', function(){
register_widget( 'MyWidget' );
$sidebars = array ('a' => 'sidebar-1' );
foreach ( $sidebars as $sidebar ) {
register_sidebar(array (
'name' => 'Footer',
'id' => $sidebar,
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>'
));
}
$active_widgets = get_option( 'sidebars_widgets' );
if ( ! empty ( $active_widgets[ $sidebars['a'] ] )){
return; }
$counter = 1;
$active_widgets[$sidebars['a']][0] = 'my_widget-'.$counter;
update_option('sidebars_widgets',$active_widgets);
dynamic_sidebar('sidebar-1');
}
Can you check with the following code?
functions. php
add_action( 'widgets_init', 'custom_sidebars' );
/*Custom widgets*/
function aavishkaar_custom_sidebars(){
register_sidebar(
array (
'name' => __( 'Footerwidget', 'Aavishkaar' ),
'id' => 'footer-widget1',
'description' => __( 'Footer widget', 'Aavishkaar' ),
'before_widget' => '<div class="col-md-2 col-3 footer-pd_0 widget_ul">',
'after_widget' => "</div>",
)
);
}
Then add menu to this and call it by <?php dynamic_sidebar('footer-widget1');?>

WPBakery Grid builder get post content

I am trying to show full content of Post in WpBakerys Grid builder
I can only add Post Excerpt but i would like to add full content not summary.I saw that I can add custom field but don't know Field key name of Post Content.
In short how can i show full post content instead of Excerpt?
You can add a custom shortcode to the Grid Builder:
add_filter( 'vc_grid_item_shortcodes', 'my_module_add_grid_shortcodes' );
function my_module_add_grid_shortcodes( $shortcodes ) {
$shortcodes['vc_post_content'] = array(
'name' => __( 'Post Content', 'my-text-domain' ),
'base' => 'vc_post_content',
'category' => __( 'Content', 'my-text-domain' ),
'description' => __( 'Show current post content', 'my-text-domain' ),
'post_type' => Vc_Grid_Item_Editor::postType(),
);
return $shortcodes;
}
// output function
add_shortcode( 'vc_post_content', 'vc_post_content_render' );
function vc_post_content_render() {
return '<p>{{ post_data:post_content }}</p>'; // usage of template variable post_data with argument "post_content"
}
Source: https://kb.wpbakery.com/docs/developers-how-tos/adding-custom-shortcode-to-grid-builder/#AddingCustomShortcodetoGridBuilder-Templatevariablesusage

activate plugins on custom theme

I'm new to Wordpress and just created my first template.
In the functions.php I have put the following code, that function what I understand should call the plugins from the plugins directory:
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => 'Widgetized Area',
'id' => 'widgetized-area',
'description' => '',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => ''
));
}
I do see all the plugins, and in the widget screen I also see the 'widgets' screen and it allows me to drag widgets into the working area.
The website itself displays the plugin's html but neither js nor css is working.
What am I missing?
Above code that you have added in your functions.php is to register sidebar not to call any plugin. It do not have any connection to plugin.
You can call sidebar you added in template as follow:
if ( is_active_sidebar( 'widgetized-area' ) ) {
dynamic_sidebar( 'widgetized-area' );
}

Wordpress: Insert html or custom function into a dynamic_sidebar('My_Sidebar')

I have registered a dynamic sidebar as follows
register_sidebar(array(
'id' => 'widget-my-header',
'name' => 'My: Header',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
));
I call the dynamic sidebar in my template.
dynamic_sidebar('widget-my-header');
Is it even possible to inject a custom function into that dynamic_sidebar('widget-my-header'); ?
Say I have a function add_my_cool_headline()
And I want that to be the content for this dynamic_sidebar('widget-my-header');
Can htis be done?
I'm using a child theme, so I'm looking to having to replace the dynamic_sidebar('widget-my-header'); with a custom action
I know how to insert my own action hook into every template page, however I'd really like to avoid that. As there are many many theme files where it needs to be changed.
Just make a class and register your widget in your sidebar
if ( function_exists('register_sidebar') ) {
register_sidebar(array('name' => 'widget-my-header','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<span>','after_title' => '</span>'));
}
class MYHeaderWidget extends WP_Widget {
function MYHeaderWidget() {
//Constructor
$widget_ops = array('classname' => 'MYHeaderWidget Widget', 'description' => 'MYHeaderWidget' );
$this->WP_Widget('MYHeaderWidget', 'widget-my-header', $widget_ops);
}
function widget($args, $instance) {
// prints the widget
extract($args, EXTR_SKIP); ?>
<div class="">Hello</div>
<?php
}
}
register_widget('MYHeaderWidget');

Resources