Best way to add internal link in widget

The page ID can vary in different installation, and it can’t be changed, so an option is to use get_page_by_path because the page slug can be easily changed: <div class=”my-link-box”> <?php $page = get_page_by_path(‘my-page’); ?> <a href=”https://wordpress.stackexchange.com/questions/126876/<?php echo get_permalink($page); ?>”><?php echo $page->post_title; ?></a> </div> However this is not a great solution as well. Once you … Read more

unregister_sidebar() in stand-alone theme not working

Thanks to Milo and G.M. for pointing to the master key, as G.M. said: you have to use a lower priority than one register_sidebar runs, but lower priority means higher number. So the final code that is working: function site_unregister_sidebar() { if ( is_admin() && current_user_can(‘editor’) ) { unregister_sidebar( ‘my_custom_widget_area’ ); } } add_action(‘widgets_init’, ‘site_unregister_sidebar’, … Read more

Check which registered sidebar a widget is added to

There isn’t a standard way to do it AFAIK in the form() method; here’s a function to do it: function wp158055_get_sidebar_id( $widget ) { foreach ( wp_get_sidebars_widgets() as $sidebar_id => $widget_ids ) { if ( array_search( $widget->id, $widget_ids ) !== false ) return $sidebar_id; } return false; } And call with $this. Note from the … Read more

How can you add a link to a sidebar description?

The sidebar description runs through esc_html(), so you cannot pass HTML directly. But you can use the filter esc_html to insert your desired content. Here is a simple example: add_action( ‘widgets_init’, function() { $desc = “Read the <a href=”http://wordpress.stackexchange.com/q/189749/73″>explanation</a>!”; $placeholder=”PLACEHOLDER”; register_sidebar([ ‘id’ => ‘wpse-189749’, ‘name’ => ‘Link description’, ‘description’ => $placeholder ]); add_action( ‘widgets_admin_page’, function() … Read more

Display sidebar if blog

There is no conditional tag for the blog page. You have to use both is_home() and is_front_page() to detect this page When you use is_home() and is_front_page(), you have to use them in the right order to avoid bugs and to test every user configuration: <?php if ( is_front_page() && is_home() ) { // blog … Read more

How to add new sidebar widget area to child theme?

Well, this is what worked for me. In my functions.php file I put the following code: function header_widgets_init() { register_sidebar( array( ‘name’ => ‘Header Sidebar’, ‘id’ => ‘header_sidebar’, ‘before_widget’ => ‘<aside class=”widget %2$s”>’, ‘after_widget’ => ‘</aside>’, ‘before_title’ => ‘<h2 class=”widget-title”>’, ‘after_title’ => ‘</h2>’, ) ); } add_action( ‘widgets_init’, ‘header_widgets_init’ ); …and in my header.php file … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)