38 posts
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+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! :)
1484 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+3 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');
1484 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+3 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
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+4 more
Thorit says

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

109 posts
  • Has sold $100+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 3 years
+1 more
Section214 says

Simple = reliable, complicated = prone to breakage!

1484 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+3 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