• Resolved Jesse Gardner

    (@plasticmind)


    It would be especially helpful if the ID of the content block that’s chosen could be passed in as a class (e.g. class=”content-block-1412″).

    Use case: I’ve got several content blocks I use in several different sidebars. I’d like to be able to define the style for a specific content block wherever it appears, but every instance of that content block widget gets a different ID. The classes, on the other hand, are too broad and every content-block widget gets the same class.

    https://www.ads-software.com/extend/plugins/custom-post-widget/

Viewing 1 replies (of 1 total)
  • Thread Starter Jesse Gardner

    (@plasticmind)

    I added this functionality to line 79 of post-widget.php:

    // Injecting our content block id into the $before_widget class
        if( strpos($before_widget, 'class') === false ) { // It has no class, add it!
            $before_widget = str_replace('>', 'class="widget-content-block-'. $custom_post_id . '"', $before_widget);
        } else { // Append existing class
            $before_widget = str_replace('class="', 'class="widget-content-block-'. $custom_post_id . ' ', $before_widget);
        }

    It will add the ID of the content block you’ve chosen as class of the widget, e.g. class=”widget-content-block-1412″.

    Hope someone else finds this useful.

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Custom Post Widget] Widget class based on content block ID’ is closed to new replies.