Here's my code:

class BWP_PostGrid {

    function __construct () {
        add_action('admin_init', array($this, 'plugin_initializer'));
        add_shortcode('bwp_post_grid', array($this, 'shortcode_callback'));
        add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
        add_action('wp_ajax_bwp_post_grid_get_data', array($this, 'bwp_post_grid_get_data'));
        add_action('wp_ajax_nopriv_bwp_post_grid_get_data', array($this, 'bwp_post_grid_get_data'));

    function plugin_initializer() {

    function shortcode_callback($shortcode_attributes) {

    function enqueue_scripts() {
        wp_enqueue_style('bwp-post-grid-styles', plugins_url('bwp-styles.css', __FILE__), false);
        wp_enqueue_script('bwp-post-grid-js', plugins_url('bwp-main.js', __FILE__), false);

    function admin_enqueue_scripts() {

    function bwp_post_grid_get_data() {

new BWP_PostGrid();

I can't get the CSS or the JavaScript files to show up in the page source.

I also checked the apache error logs... no errors.

  • Is this in the main plugin file or a file in a subfolder? – Jacob Peattie Oct 14 '17 at 9:38
  • This is in the main plugin file, which exists in a folder within the plugins folder. plugins/my-plugin/my-plugin.php – Blaine Lafreniere Oct 14 '17 at 9:40
  • This function doesn’t appear to be hooked anywhere. Is that in your actual code? – Jacob Peattie Oct 14 '17 at 9:44
  • I omitted that code because I didn't think it was relevant. I've added more context to my question in case that helps. – Blaine Lafreniere Oct 14 '17 at 9:50
  • Is the enqueue_scripts() method actually being run? Is wp_head() executed? Is wp_print_scripts still attached to wp_head? – janh Oct 14 '17 at 10:23

I figured out the problem. It was working all along. The site I'm working on had installed a plugin called 'Autoptimize' which will shove all your CSS into an inline <style> tag. I was trying to search the output HTML for a reference to my CSS file, but it wasn't there, because this plugin was removing it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.