Sanjay Yadav
Sanjay Yadav

Reputation: 241

WordPress directory path issues in js file

I am unable to give proper path of root directory link, error is showing "http://localhost/wordpress/alerts.php 404 (Not Found) " alerts.php file theme folder main directory .

 .directive('alertsCenter', function () {
        return {
          templateUrl: 'alerts.php',
          replace:true,
          restrict: 'E',
          controller:'alertsCtrl'
        };
    }); 

Upvotes: 0

Views: 307

Answers (1)

vrajesh
vrajesh

Reputation: 2942

Try this :

Use get_template_directory() function if you added file inside active theme folder

function print_my_inline_script() {
  if ( wp_script_is( 'some-script-handle', 'done' ) ) {
?>
<script type="text/javascript">
//PASTE YOUR ALL JAVASCRIPT CODE
.directive('alertsCenter', function () {
        return {
          templateUrl: '<?php echo get_template_directory(); ?>/alerts.php',
          replace:true,
          restrict: 'E',
          controller:'alertsCtrl'
        };
    });
</script>
<?php
  }
}

add_action( 'wp_footer', 'print_my_inline_script' );

Upvotes: 0

Related Questions