• Hi guys.

    I’m a beginner when it comes to PHP, and I don’t know much about CSS either. All I know is the basics. By looking at guides and manuals online and from books, I’ve learned how to create a basic widget and the basics of PHP, and I’ve also made a big website, a rather advanced one actually. Now I’m trying to make a more advanced widget. I’ll use the widget on pages (not sidebars).

    My problem is, I want to have a stylesheet of my own for my widget, but I can’t get it to work.
    I need to call my own stylesheet, and also override the global stylesheet used by the theme.

    My widget is still very basic, it’s just an upgraded and edited ‘example’ widget. But I can’t get anywhere unless I figure out how to properly call my stylesheet.
    This is how my widget code looks at the moment (it’s a snippet of my full plugin php):

    function add_style() {
    		wp_register_style('belimo-style', '/style.php', false, false, "screen");
    		wp_enqueue_style('belimo-style');
    	}
    
    function widget($args, $instance)
      {
        extract($args, EXTR_SKIP);
    
        echo $before_widget;
        $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
        $name = $instance['name'];
    
        if (!empty($title))
          echo $before_title . $title . $after_title;;
    
        if ( $name )
          printf( '<p>' . __('%1$s.', 'example') . '</p>', $name );
    
        /*Widget stuff here... */
    
     	add_action( 'wp_print_styles', 'add_style');
    
    	echo ("<link href=\"style.php\" rel=\"stylesheet\"   type=\"text/css\">");
    
    	include('widget.php');
    
        echo $after_widget;
    }

    The “widget.php” included in the function is basically empty at the moment.

    Obviously it’s not a good looking code, you probably face palmed or slammed your forehead on the desk and yelled “blaspheme!” or something, but I’m an absolute amateur as I said before.

    I would be so grateful if someone would help me with this, I know us “noobs” are annoying with our stupid questions and all that, but I’d REALLY appreciate it. I’m just trying to learn.

    If you need more information, I’ll reply immediately.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter tapper101

    (@tapper101)

    Before you ask, yes I (tried) to call the stylesheet twice. I tried them both individually at first, none of them worked. I was frustrated and added both of them at the same time and whatever else I could find, to create this wonderful clusterf#ck.

    Thread Starter tapper101

    (@tapper101)

    Anyone?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Widget] Overriding a themes style in a widget’ is closed to new replies.