/* NewsMag Pro — theme setup: menus, sidebars, a custom Text-Link (backlink) widget, thumbnails. */
if (!defined('ABSPATH')) exit;
add_action('after_setup_theme', function () {
add_theme_support('title-tag');
add_theme_support('post-thumbnails');
add_theme_support('automatic-feed-links');
add_theme_support('html5', ['search-form','comment-form','comment-list','gallery','caption','style','script']);
register_nav_menus(['primary' => 'Primary Menu']);
});
add_action('widgets_init', function () {
register_sidebar([
'name' => 'Sidebar', 'id' => 'sidebar-1',
'before_widget' => '',
'before_title' => '
', 'after_title' => '
',
]);
register_sidebar([
'name' => 'Footer Links', 'id' => 'footer-1',
'before_widget' => '', 'after_widget' => '
',
'before_title' => '', 'after_title' => '
',
]);
});
/* Custom widget: an editable TEXT-LINK (backlink) block for the sidebar / footer.
Stores one per line ("Anchor|https://url|dofollow"). Placeholder-friendly. */
class NewsMag_TextLinks_Widget extends WP_Widget {
function __construct() {
parent::__construct('newsmag_textlinks', 'NewsMag: Text Links (backlink)',
['description' => 'Editable text-link block. One per line: Anchor|URL|rel(dofollow/nofollow)']);
}
function widget($args, $instance) {
$title = !empty($instance['title']) ? $instance['title'] : 'Useful Links';
$raw = isset($instance['links']) ? $instance['links'] : '';
echo $args['before_widget'];
echo '';
echo '';
echo $args['after_widget'];
}
function form($instance) {
$title = isset($instance['title']) ? $instance['title'] : 'Useful Links';
$links = isset($instance['links']) ? $instance['links'] : '';
echo '';
echo '';
}
function update($new, $old) {
return ['title' => sanitize_text_field($new['title']), 'links' => trim($new['links'])];
}
}
add_action('widgets_init', function () { register_widget('NewsMag_TextLinks_Widget'); });
/* Excerpt length + read-more */
add_filter('excerpt_length', function () { return 22; });
add_filter('excerpt_more', function () { return '…'; });
/* Helper: anh dai dien bai; bai chua co anh -> anh bia mac dinh cua site (option newsmag_default_thumb = attachment ID),
alt = tieu de bai. Khong co ca hai -> o placeholder nhu cu. */
function newsmag_thumb($size = 'large') {
if (has_post_thumbnail()) { the_post_thumbnail($size); return; }
$fid = (int) get_option('newsmag_default_thumb');
if ($fid && wp_attachment_is_image($fid)) { echo wp_get_attachment_image($fid, $size, false, ['alt' => get_the_title()]); return; }
echo 'Featured
';
}
/* Style cho khoi gioi thieu trang chu + tieu de hero (h2) */
add_action('wp_head', function () {
if (!is_front_page()) return;
echo '' . "\n";
}, 20);
/* Helper: category name of a post (first) */
function newsmag_cat($id = null) {
$c = get_the_category($id);
return $c ? $c[0]->name : 'News';
}
Health
Health
Nothing found.