簡體   English   中英

js文件中的WordPress目錄路徑問題

[英]WordPress directory path issues in js file

我無法提供根目錄鏈接的正確路徑,錯誤顯示“ http://localhost/wordpress/alerts.php 404(未找到)” alert.php文件主題文件夾主目錄。

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

嘗試這個 :

如果您在活動主題文件夾中添加了文件,請使用get_template_directory()函數

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' );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM