• Resolved lucavalentino

    (@lucavalentino)


    In a personal class I’m trying to load css and js, but it doesn’t work.
    This is the class

    <?php
    namespace test_name;
    class All_name_page{
    function __construct()
    {
    add_action( 'wp_enqueue_scripts', 'my_assets' );
    }
    function index($data){
    $content = '<h1>All ex-alunni page</h1><br>';
    $content.='<table>';
    $content.= '<tr><td>Name</td></th>';

    foreach ($data as $key=>$ea){
    $content.= '<tr>';
    $content.= '<td>'.$ea->Name.'</td>';
    $content.='</tr>';
    }
    $content.='</table>';
    return $content;
    }

    function my_assets() {
    wp_register_style( 'datatables-css', plugin_url('//cdn.datatables.net/v/dt/dt-2.1.3/datatables.min.css'),array(), 'false','true');
    wp_register_script( 'datatables-js', '//cdn.datatables.net/v/dt/dt-2.1.3/datatables.min.js', array('jquery'),'false','true');
    }
    }
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter lucavalentino

    (@lucavalentino)

    I tried with the code below, but without success.
    The index function has not changed
    function __construct()
    {
    add_action('wp_enqueue_scripts', array($this, 'my_assets') );
    }

    function my_assets() {
    wp_enqueue_style('datatables-css', 'https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css', array(), null);
    wp_enqueue_script('datatables-js', 'https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js', array('jquery'), null, true);
    // Initialize DataTables via custom script
    wp_add_inline_script('datatables-js', 'jQuery(document).ready(function($) { $("table").DataTable(); });');
    }


    • This reply was modified 1 year, 10 months ago by lucavalentino.
    Thread Starter lucavalentino

    (@lucavalentino)

    Thanks I solved it.
    I was not loading the class in the main file of the plugin

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘load css re js not working’ is closed to new replies.