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
+3 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! :)
1512 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
+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');
1512 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
+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
  • 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
+3 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 4 years
+1 more
Section214 says

Simple = reliable, complicated = prone to breakage!

1512 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
+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.

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by