$url = moodle_url::current(); $anchor = "Jump to Footer"; $url->set_anchor($anchor); echo $url;
$url = new moodle_url('/my/course/view.php', array('id' => 10)); $anchor = "Jump to Comments"; $url->set_anchor($anchor); echo $url;
$url = new moodle_url('/my/course/view.php', array('id' => 10)); $anchor = "Jump to Comments"; $url->set_anchor($anchor, array('class' => 'comment-link')); echo $url;Explanation: This code sets an anchor link with the text "Jump to Comments" on a specific course page URL and adds a custom CSS class called "comment-link". The `echo` statement will display the URL with the anchor link and the custom class. Package library: Moodle Core.