Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress How to Build a WordPress Plugin Building WordPress Widgets, and Shortcodes Adding Custom Styles to Plugin Front End

Richard Hope
Richard Hope
25,237 Points

Error thrown when enqueuing js file

I have been doing this course using the wp site that was developed in the bootstrap to wordpress course.

After adding the the line to enqueue the js file an error is displayed on the front-end as follows:

' Warning: strpos() expects parameter 1 to be string, array given in C:\xampp\htdocs\bootstraptowordpress\wp-includes\link-template.php on line 2836'

The code I added to enqueue the css and js files is as follows:

function wptreehouse_badges_frontend_scripts_and_styles() {

wp_enqueue_style( 'wptreehouse_frontend_css', plugins_url( 'wptreehouse-badges/wptreehouse-badges.css' ) );
wp_enqueue_script( 'wptreehouse_frontend_js', plugins_url( 'wptreehouse-badges/wptreehouse-badges.js', array('jquery'), '', true ) );

}

add_action( 'wp_enqueue_scripts', 'wptreehouse_badges_frontend_scripts_and_styles' );

The code referred to in the error is as follows:

function plugins_url( $path = '', $plugin = '' ) {

$path = wp_normalize_path( $path );
$plugin = wp_normalize_path( $plugin );
$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );

if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) )
    $url = WPMU_PLUGIN_URL;
else
    $url = WP_PLUGIN_URL;

Does anyone have any idea why this is happening?

Richard Hope
Richard Hope
25,237 Points

I should also mention that the error does not occur if I comment out the line to enqueue the js file ie:

wp_enqueue_script( 'wptreehouse_frontend_js', plugins_url( 'wptreehouse-badges/wptreehouse-badges.js', array('jquery'), '', true ) );

Ben Attenborough
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ben Attenborough
Front End Web Development Techdegree Graduate 32,769 Points

Hmm, that's a bit odd. Given the error it looks like strpos is being given an array. So perhaps try echoing out or vardumping $plugin to see if it is an array and the same with $mu_plugin_dir. Perhaps enqueuing the script is turning one of these variables into an array

1 Answer

For future people with this issue. I had the same problem. All the jQuery does is fade in and fade the tool tip. Just remove the enqueue_script it's not needed.