Menu bar

Showing posts with label shortcode. Show all posts
Showing posts with label shortcode. Show all posts

Monday, 22 December 2014

How to show or hide specific widget on specific page?


SHOW OR HIDE SPECIFIC WIDGETS ON SPECIFIC PAGES

Did you ever think to show or hide your WordPress widgets on selective pages...of course you can thought of.Because there are some wordpress widgets that should be display on certain pages to make websites look better then before.

You can do this task by putting this snippet in your function files....

Here you have to change the widgetname to name of the widget to show or hide and you can get that name by inspecting your code..

Change the pagename to the name of page on which the widget to be show or hide and this is the slug name of your page...

//Show widget on particular page..
add_filter( 'widget_display_callback', 'show_hide_widget', 10, 3 );
function show_hide_widget( $instance, $widget, $args ) {
  if ( $widget->id_base == 'widgetname' ) { 
     if ( !is_page( 'pagename' ) ) {
         return false;
     }
  }
}

//Hide widget on particular page..
add_filter( 'widget_display_callback', 'show_hide_widget', 10, 3 );
function show_hide_widget( $instance, $widget, $args ) {
  if ( $widget->id_base == 'widgetname' ) { 
     if ( is_page( 'pagename' ) ) {
         return false;
     }
  }
}

Even there is a plugin used to perform this task and the name of the plugin is "Display Widgets".

Saturday, 1 November 2014

Turn on WordPress Error Reporting


How to turn on error reporting for testing your website?


Sets error reporting to true in wordpress  indicates which PHP errors are reported

Comment out the top line there, and add the rest to your wp-config.php file to get more detailed error reporting from your WordPress site. Definitely don't do this live, do it for local development and testing.

// define('WP_DEBUG', false); define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false); @ini_set('display_errors', 0);
This changes will be done in wp-config.php
This will log all errors notices and warnings to a file called debug.log in wp-content (if Apache does not have write permission, you may need to create  the file first and set the appropriate permissions (i.e. use 666) )

Tuesday, 15 July 2014

How to add shortcode in a widgets?

How to add shortcode means how to make shortcode runnable when paste  in a widget section.


277341190 3f098a08a4 t The Right Way To Shortcodize WordPress Widgets


Most advice on this converges to this simple line of code:
add_filter('widget_text', 'do_shortcode');
Though a wide spread method, this is not quite correct. The more correct way would be:
if (!is_admin())
  add_filter('widget_text', 'do_shortcode', 11);


if (!is_admin())
  add_filter('widget_text', 'do_shortcode', SHORTCODE_PRIORITY);


to avoid guessing what the number 11 means, but SHORTCODE_PRIORITY is a constant the WordPress team has yet to provide.