Plugin, path to the content folder giving 404 error
-
HI all,
I am new to plug in development, but am impressed with the support and documentation. I have been able to implement a Gutenberg Block plugin and enter all the variables I want. It’s now time to implement the javascript and php render pages (edit.js and render.php). The purpose of my plugin is to enable display of createjs animations. The php code to do this will be the following:
<?php
if(!empty($attributes['javascriptPath']) && !empty($attributes['canvasWidth']) && !empty($attributes['canvasHeight'])){
$javascript_path = $attributes['javascriptPath'];
$canvas_width = $attributes['canvasWidth'];
$canvas_height = $attributes['canvasHeight'];
}
?>
<div>
<canvas id="PEPSyn" width="<?php echo $canvas_width ?>" height="<?php echo $canvas_height ?>" class="default">
</canvas>
<script src="<?php echo WP_CONTENT_DIR . $javascript_path ?>"></script>
<script>
;
</script>
</div>I want the plugin user to be able to enter a width and height for the canvas page and also a path to the javascript file that creates the animation. The problem I am having is I keep getting errors when I try to point to the js file in the content directory. I have placed the file in the content directory like so…
wp-content:images: 8-9.jsI am thinking the path should be images/8-9.js and when I use that and render the page, I get this path
http://localhost/wordpress_ttm/2025/08/25/copyright-test-page/images/8-9.jsThat is the incorrect path. Even when I hard code in what I think is the right path (wp-content/images/8-9.js) I still get a Loading failed for the <script> with source error. What is the right way to do this in the PHP file and in the edit.js file?
You must be logged in to reply to this topic.