38 posts
  • Author Level 4
  • Beta Tester
  • Collector Level 4
  • Featured Author
+4 more
Thorit
says
How can i includ a stylesheet via wp_enqueue_style for an seperated file within a plugin? the file displays the latest post from a custom post type. Wordpress functions are included via: <?php $rel_path = "../../../../"; include ($rel_path . 'wp-blog-header.php'); ?> <?php POST LOOP etc. ?> file strucutre: plugin directory
  • pluginname.php (config)
  • 2 Directory) index.php <- i want to includ the main.css stylesheet in this file via wp_enqueue_style
  • 2 Directory) main.css
    • Thanks! :)
1565 posts
  • Affiliate Level 2
  • Author Level 5
  • Collector Level 2
  • Featured Author
+2 more
OriginalEXE
says
Put this in your main plugin file:
define( 'YOURPREFIX_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
and then use it like this:
wp_enqueue_style('stylesheet-name', YOURPREFIX_PLUGIN_URL. 'folder-name/name-of-css.css');
1565 posts
  • Affiliate Level 2
  • Author Level 5
  • Collector Level 2
  • Featured Author
+2 more
OriginalEXE
says

Also, what you are doing is bad. You should not call for WordPress functions again, unless it is absolutely necessary (for example, with forms).

You should include the index.php file in your main plugin file, that way you will also have access to wp functions in that included file.

38 posts
  • Author Level 4
  • Beta Tester
  • Collector Level 4
  • Featured Author
+4 more
Thorit
says

Oh thanks for your reply! Why make it simple if there’s a complicated way to do it? :D

111 posts
  • Author Level 2
  • Collector Level 4
  • Copyright Ninja
  • Exclusive Author
+2 more
Section214
says

Simple = reliable, complicated = prone to breakage!

1565 posts
  • Affiliate Level 2
  • Author Level 5
  • Collector Level 2
  • Featured Author
+2 more
OriginalEXE
says

Oh thanks for your reply! Why make it simple if there’s a complicated way to do it? :D

Well it’s not only about simplicity this time (although that alone is enough for me :) ), but also about speed.

When you include wp-blog-header.php, you run WordPress once more, meaning that you are taking away from speed. Now, that might not be some noticable slowdown, but it is, and if it’s not required, why do it :)

Cheers.

by
by
by
by
by
by