38 posts
  • Envato Studio (Microlancer) Beta Tester
  • Sold between 5 000 and 10 000 dollars
  • Grew a moustache for the Envato Movember competition
  • Europe
  • Exclusive Author
  • Has been a member for 2-3 years
  • Bought between 100 and 499 items
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! :)
1466 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Croatia
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');
1466 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Croatia
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
  • Envato Studio (Microlancer) Beta Tester
  • Sold between 5 000 and 10 000 dollars
  • Grew a moustache for the Envato Movember competition
  • Europe
  • Exclusive Author
  • Has been a member for 2-3 years
  • Bought between 100 and 499 items
Thorit says

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

106 posts
  • Sold between 100 and 1 000 dollars
  • Exclusive Author
  • Has been a member for 3-4 years
  • Bought between 100 and 499 items
  • United States
Section214 says

Simple = reliable, complicated = prone to breakage!

1466 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Croatia
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