Tag Info

New answers tagged

0

You can do something like this inside your functions.php: add_action( 'wp_head', 'dynamic_layout' ); function dynamic_layout() { echo '<style type="text/css">'; if ( is_active_sidebar( 'secondary' ) && is_active_sidebar( 'main' ) ) {//If both sidebars are active ?> #blog { width: 100%; } <?php } // End If both sidebars are active ...


0

You can use is_active_sidebar() as a condition to enqueue your styles. It does precisely that — tells you if it has any widgets assigned. PS stop function_exists() madness :) that is completely pointless check in modern WordPress.


0

On default is each site in the network a single site in the context, menu, settings, widgets. But you can sync about custom source or plugins, like http://wordpress.org/extend/plugins/wp-multisite-mirror/ http://wordpress.org/extend/plugins/yd-wpmu-sitewide-options/ Also you can use the Multilingual Press plugin. This have a API fit synchronization about ...


0

Here is a cleaner method which does not skip the first post in the loop As this is the main query on the home page, we can do the following: Use pre_get_posts to alter the main query on the homepage so as to set an offset of one so that the newest post is ignored Recalculate the amount of posts found so that pagination works correctly in calculating the ...


0

You can write the logic inside widget functions. When the widget is added in sidebar, it will check for sidebar name and home page. global $wp_registered_widgets, $wp_registered_sidebars; $sidebars_widgets = get_option('sidebars_widgets'); if($sidebars_widgets["sidebar-1"] && is_home()) { //Write your logic here }


0

Alright, so I managed to pull it off thanks to @toscho! =D He gave me this link: Add class to before_widget for all widgets with a dropdown and a counter I kind of worked up through it. All I wanted to do was add one class "col-sm-4" from Bootstrap to the search widget. is_admin() || add_filter( 'dynamic_sidebar_params', 'wpse172754_add_widget_classes' ); ...


0

There is a plugin with which you can add more CSS classes and ID's to a widget. It's called Widget CSS Classes. Pretty handy, take a look: https://wordpress.org/plugins/widget-css-classes/


0

Hey you can add class in before_widget something like this if ( function_exists('register_sidebar') ) register_sidebar(array( 'name' => 'Your Widget Name', 'description' => 'Description of your widget', 'before_widget' => '<div class="container-top">', 'after_widget' => '</div>', 'before_title' ...


0

Also, you can write a function in the functions.php file and call that function via the widget. Functions.php: function myFunction() { //do something here } add_shortcode('wp_my_function', 'myFunction'); //Allow write shortcode in widgets add_filter('widget_text', 'do_shortcode'); In the Widget: Use the text widget, write in the shortcode: ...


0

Yes by using widget_text inject content into the widget area Add the following code into your function.php file function widget_content( $content ) { // add $content as you want return $content; } add_filter( 'widget_text', 'widget_content', 99 );


1

I believe if you add 'title' field to the form() (and update()) method this will be displayed in the admin interface. Traditionally this would also be used in the widget() method, but is not required. function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); ...


1

Widgets DO appear in the Customizer, but only if you are on the page that they are used on. For example, I have a sidebar for the Archive page. When I'm in the Customizer and on the homepage, that sidebar doesn't appear. But if I navigate to an archive page while in the Customizer, it then appears in the widget area.


0

OK, attempting to remove the with jQuery is counter intuitive. Modifying it via output buffering is inefficient. And we shouldn't edit the actual widget code itself, since this will revert back next time we update WordPress. I would suggest either creating your own text widget, or simply extend and modify the existing WordPress widget as follows (put the ...


1

This should just be an extension to the answer by @Milo There are a couple of flaws in your code You should not be using extract(). It is hard to debug and causes unexpected output. All instances of extract() was removed from core PHP 5.2 is dead, and for that matter 5.3 aswell. create_function() is pre 5.3. This is one big security risk as it uses eval() ...


1

Technically your first example is also incorrect, but the problem is not apparent. You're using template tags that themselves echo their content. For example, you can write simply: the_permalink(); without echo, and the permalink will be output. This is because that function echoes its value. To output the permalink within an echo or variable assignment ...


0

It looks like it can be a selector issue. Try making your selector more specific for the widget in the sidebars: Something like : $('#widgets-right #widget-so_calendar_excerpt-range_from') could work. But, if you create a second instance of the widget, it can break again, because of the multiple same ids.


0

Found a 'dirty' way to do it: Here's my code: $sidebar_id = 'sidebar1'; $sidebars_widgets = wp_get_sidebars_widgets(); $widget_ids = $sidebars_widgets[$sidebar_id]; foreach( $widget_ids as $id ) { $wdgtvar = 'widget_'._get_widget_id_base( $id ); $idvar = _get_widget_id_base( $id ); $instance = get_option( $wdgtvar ); ...


0

If you want to just display all the widgets coming from a specific sidebar, try dynamic_sidebar. Example taken from the Codex: <?php if ( is_active_sidebar( 'left-sidebar' ) ) : ?> <ul id="sidebar"> <?php dynamic_sidebar( 'left-sidebar' ); ?> </ul> <?php endif; ?> If you're trying to get a specific widget and ...


0

I think your idea is really nice here, but you have a couple of serious flaws in your code. Never use extract(), ever. It is extremely hard to debug and can render unexpected output. It has now been completely removed from core, except in one instance as far as I can pick up from this core trac ticket. The codex has also been updated to reflect this ...


0

I would suggest this, which moves specific 'block-level' shortcodes outside of 'p' elements without affecting those elsewhere that may be intended to be inline: function my_fix_shortcodes($content){ if (strpos($content, '<p>') !== false) { /* Move 'block level' shortcode tags outside <p> elements by surrounding with ...


0

Could you use the admin bar at the top instead? To me short messages look better up there. add_action( 'admin_bar_menu', 'toolbar_link_to_mypage', 999 ); function toolbar_link_to_mypage( $wp_admin_bar ) { $args = array( 'id' => 'my_admin_bar_text', 'title' => 'WELCOME TO SYDNEY', 'meta' => array( 'class' => ...


1

Use This <?php class Game_Info_Widget extends WP_Widget { /** * Register widget with WordPress. */ public function __construct() { parent::__construct( 'game_info_widget', // Base ID 'Game - Info', // Name array('description' => __('Game - ...


1

There are 3 issues. Firstly, you're calling do_action, triggering the action: do_action( 'wp_print_footer_scripts', 'tab_widget_scripts' ); When actually, you want to add your function to it, not trigger it. You should be doing this: add_action( 'wp_print_footer_scripts', 'tab_widget_scripts' ); Secondly, you're registering this script: tabs Then ...


1

do_action should be add_action - you're adding a function to the queue, not executing all functions hooked to the action. That said, you don't have to hook a separate function, you can just enqueue directly in the widget function if you want.


1

As @aaron-holbrook commented a cleaner approach will be to do: <script> $(document).on('widget-updated widget-added', function(){ // your code to run }); </script> Just pasting here for reference as answers are much easier to find that comments


0

I don't have enough reputation to reply to comment on your answer, so I will post it here: I had similar problem, and answer why class selector works (and id don't) is because on widgets page, that element appears twice (on left side to select it and drag to the right), and on the right side, in appropriate sidebar area. So, that element and everything in it ...



Top 50 recent answers are included