Make WordPress Themes

source: meta-write/1.0.0/functions.php

Last change on this file was 297762, checked in by themedropbox, 2 weeks ago

New theme: Meta Write - 1.0.0

File size: 32.4 KB
Line 
1<?php
2/**
3 * Meta Write functions and definitions
4 *
5 * @link https://developer.wordpress.org/themes/basics/theme-functions/
6 *
7 * @package Meta_Write
8 * @since 1.0.0
9 */
10
11if ( ! defined( '_S_VERSION' ) ) {
12        define( '_S_VERSION', '1.0.0' );
13}
14
15function meta_write_setup() {
16    // Translation Support
17    load_theme_textdomain( 'meta-write', get_template_directory() . '/languages' );
18
19    // RSS Feed Links
20    add_theme_support( 'automatic-feed-links' );
21
22    // Title Tag Support
23    add_theme_support( 'title-tag' );
24
25    // Featured Images
26    add_theme_support( 'post-thumbnails' );
27
28    // Navigation Menu
29    register_nav_menus(
30        array(
31            'menu-1' => esc_html__( 'Primary', 'meta-write' ),
32        )
33    );
34
35    // HTML5 Markup Support
36    add_theme_support(
37        'html5',
38        array(
39            'search-form',
40            'comment-form',
41            'comment-list',
42            'gallery',
43            'caption',
44            'style',
45            'script',
46        )
47    );
48
49    // Custom Background
50    add_theme_support(
51        'custom-background',
52        array(
53            'default-color' => 'ffffff',
54            'default-image' => '',
55        )
56    );
57
58    // Custom Logo
59    add_theme_support(
60        'custom-logo',
61        array(
62            'height'      => 250,
63            'width'       => 250,
64            'flex-width'  => true,
65            'flex-height' => true,
66        )
67    );
68
69    // Widgets Selective Refresh
70    add_theme_support( 'customize-selective-refresh-widgets' );
71
72    // Block Editor Features
73    add_theme_support( 'wp-block-styles' );
74    add_theme_support( 'align-wide' );
75    add_theme_support( 'responsive-embeds' );
76    add_theme_support( 'woocommerce' );
77
78    // Editor Style
79    add_editor_style( 'editor-style.css' );
80}
81add_action( 'after_setup_theme', 'meta_write_setup' );
82
83/**
84 *
85 * Priority 0 to make it available to lower priority callbacks.
86 *
87 * @global int $content_width
88 */
89function meta_write_content_width() {
90        $GLOBALS['content_width'] = apply_filters( 'meta_write_content_width', 1200 );
91}
92add_action( 'after_setup_theme', 'meta_write_content_width', 0 );
93
94/**
95 * Register widget area.
96 *
97 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
98 */
99function meta_write_widgets_init() {
100        register_sidebar(
101                array(
102                        'name'          => esc_html__( 'Sidebar', 'meta-write' ),
103                        'id'            => 'sidebar-1',
104                        'description'   => esc_html__( 'Add widgets here.', 'meta-write' ),
105                        'before_widget' => '<section id="%1$s" class="widget %2$s">',
106                        'after_widget'  => '</section>',
107                        'before_title'  => '<h2 class="widget-title">',
108                        'after_title'   => '</h2>',
109                )
110        );
111}
112add_action( 'widgets_init', 'meta_write_widgets_init' );
113
114// Elementor basic compatibility
115function meta_write_elementor_support() {
116    // Define content width for Elementor
117    global $content_width;
118    if ( ! isset( $content_width ) ) {
119        $content_width = 1200; // px
120    }
121
122    // Hook into Elementor init
123    add_action( 'elementor/init', function() {
124        if ( class_exists( '\Elementor\Plugin' ) && isset( \Elementor\Plugin::$instance->themes_manager ) ) {
125            \Elementor\Plugin::$instance->themes_manager->register_all_core_location();
126        }
127    });
128}
129add_action( 'after_setup_theme', 'meta_write_elementor_support' );
130
131/**
132 * Enqueue scripts and styles.
133 */
134function meta_write_scripts() {
135        wp_enqueue_style( 'meta-write-style', get_stylesheet_uri(), array(), _S_VERSION );
136        wp_style_add_data( 'meta-write-style', 'rtl', 'replace' );
137
138        wp_enqueue_script( 'meta-write-navigation', get_template_directory_uri() . '/js/navigation.js', array(), _S_VERSION, true );
139
140        if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
141                wp_enqueue_script( 'comment-reply' );
142        }
143}
144add_action( 'wp_enqueue_scripts', 'meta_write_scripts' );
145
146//dark mode svg color change start here
147function custom_theme_scripts() {
148    wp_enqueue_style('theme-style', get_stylesheet_uri());
149     wp_add_inline_script('jquery-core', "
150        document.addEventListener('DOMContentLoaded', function () {
151            const toggleBtn = document.getElementById('darkModeToggle');
152            if (toggleBtn) {
153                toggleBtn.addEventListener('click', function () {
154                    document.body.classList.toggle('dark-mode');
155                    localStorage.setItem('theme', document.body.classList.contains('dark-mode') ? 'dark' : 'light');
156                });
157            }
158            // Restore theme from localStorage
159            const savedTheme = localStorage.getItem('theme');
160            if (savedTheme === 'dark') {
161                document.body.classList.add('dark-mode');
162            }
163        });
164    ");
165}
166add_action('wp_enqueue_scripts', 'custom_theme_scripts');
167//dark mode svg color change end here
168
169/**
170 * Implement the Custom Header feature.
171 */
172require get_template_directory() . '/inc/custom-header.php';
173
174/**
175 * Custom template tags for this theme.
176 */
177require get_template_directory() . '/inc/template-tags.php';
178
179/**
180 * Functions which enhance the theme by hooking into WordPress.
181 */
182require get_template_directory() . '/inc/template-functions.php';
183
184/**
185 * Customizer additions.
186 */
187require get_template_directory() . '/inc/customizer.php';
188
189/**
190 * Load Jetpack compatibility file.
191 */
192if ( defined( 'JETPACK__VERSION' ) ) {
193        require get_template_directory() . '/inc/jetpack.php';
194}
195
196function meta_write_enqueue_scripts() {
197    // Enqueue customizer.js
198    wp_enqueue_script(
199        'meta-write-customizer',
200        get_template_directory_uri() . '/js/customizer.js',
201        array('jquery'), // dependencies
202        '1.0.0',
203        true // true = load in footer
204    );
205}
206add_action('wp_enqueue_scripts', 'meta_write_enqueue_scripts');
207
208/* ==========================================================
209   // All post seraching function start here(Live search)
210============================================================= */
211add_action('wp_ajax_fetch_posts_by_tag', 'fetch_posts_by_tag');
212add_action('wp_ajax_nopriv_fetch_posts_by_tag', 'fetch_posts_by_tag');
213
214function fetch_posts_by_tag() {
215    if (!empty($_POST['tag'])) {
216        $search_term = sanitize_text_field($_POST['tag']);
217        $is_single_char_search = (strlen($search_term) === 1);
218
219        //  Main Query Args
220        $args = array(
221            'post_type'      => 'post',
222            'posts_per_page' => 10,
223            'post_status'    => 'publish',
224        );
225
226        //  Single Character Search
227        if ($is_single_char_search) {
228            $custom_where_filter = function($where) use ($search_term) {
229                global $wpdb;
230                $where .= " AND (
231                    {$wpdb->posts}.post_title LIKE '{$search_term}%'
232                    OR {$wpdb->posts}.post_content LIKE '{$search_term}%'
233                    OR EXISTS (
234                        SELECT 1 FROM {$wpdb->terms}
235                        INNER JOIN {$wpdb->term_taxonomy} ON {$wpdb->terms}.term_id = {$wpdb->term_taxonomy}.term_id
236                        INNER JOIN {$wpdb->term_relationships} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id
237                        WHERE {$wpdb->term_relationships}.object_id = {$wpdb->posts}.ID
238                        AND (
239                            {$wpdb->terms}.name LIKE '{$search_term}%'
240                            OR {$wpdb->terms}.slug LIKE '{$search_term}%'
241                        )
242                    )
243                )";
244                return $where;
245            };
246            add_filter('posts_where', $custom_where_filter);
247        } else {
248            $args['s'] = $search_term;
249            $args['tax_query'] = array(
250                'relation' => 'OR',
251                array(
252                    'taxonomy' => 'post_tag',
253                    'field'    => 'name',
254                    'terms'    => $search_term,
255                    'operator' => 'LIKE',
256                ),
257                array(
258                    'taxonomy' => 'category',
259                    'field'    => 'name',
260                    'terms'    => $search_term,
261                    'operator' => 'LIKE',
262                ),
263            );
264        }
265        $query = new WP_Query($args);
266        if ($is_single_char_search && isset($custom_where_filter)) {
267            remove_filter('posts_where', $custom_where_filter);
268        }
269        if ($query->have_posts()) :
270            ob_start(); ?>
271            <div class="mw-recently-scroll-wrapper">
272                <?php while ($query->have_posts()) : $query->the_post(); ?>
273                    <div class="mw-recently-blog-card">
274                        <img src="<?php echo esc_url(get_the_post_thumbnail_url(get_the_ID(), 'medium')); ?>" class="mw-recently-img" alt="Post Image" />
275                        <div class="mw-recently-blog-details">
276                            <span class="mw-recently-tag">
277                    <?php
278                    $tags = get_the_tags();
279                    if ($tags) {
280                        foreach ($tags as $tag) {
281                            $tag_link = get_tag_link($tag->term_id);
282                            echo '<a href="' . esc_url($tag_link) . '" class="post-title-tags-link">' . esc_html($tag->name) . '</a> ';
283                        }
284                    }
285                    ?>
286                </span>
287                <h4>
288                    <a href="<?php the_permalink(); ?>" class="mw-tag-serach-title text-decoration-none">
289                            <?php the_title(); ?>
290                         </a>
291                    </h4>
292                <p>
293                        <?php
294                        $content = get_the_content();
295                        $trimmed_content = wp_trim_words($content, 15, '');
296                         echo esc_html($trimmed_content);
297                        ?>
298                                <a href="<?php the_permalink(); ?>" class="text-decoration-none">Read More</a>
299                            </p>
300                        </div>
301                    </div>
302                <?php endwhile; ?>
303            </div>
304            <?php
305            wp_reset_postdata();
306            echo ob_get_clean();
307        else :
308            echo '<p style="color: red;">No posts found matching your search.</p>';
309        endif;
310    } else {
311        echo '<p style="color: red;">Please enter a search term.</p>';
312    }
313
314    wp_die();
315}
316function enqueue_lazy_load_scripts() {
317    wp_enqueue_script(
318        'custom-lazy-load',
319        get_template_directory_uri() . '/assets/js/lazy-load.js',
320        [],
321        null,
322        true
323    );
324
325    wp_localize_script('custom-lazy-load', 'my_ajax_object', [
326        'ajax_url' => admin_url('admin-ajax.php'),
327    ]);
328}
329add_action('wp_enqueue_scripts', 'enqueue_lazy_load_scripts');
330/* ==========================================================
331   // All post seraching function End here(Live search)
332============================================================= */
333// Enqueue JS and pass ajax_url
334function enqueue_live_search_scripts() {
335    wp_enqueue_script('live-tag-search', get_template_directory_uri() . '/js/live-tag-search.js', array('jquery'), null, true);
336    wp_localize_script('live-tag-search', 'my_ajax_object', array(
337        'ajax_url' => admin_url('admin-ajax.php')
338    ));
339}
340/* ==========================================================
341   //All css js and fonts enqueue style start here
342============================================================= */
343function metawrite_enqueue_local_scripts() {
344    // Bootstrap CSS
345    wp_enqueue_style(
346        'bootstrap-css',
347        get_template_directory_uri() . '/assets/css/bootstrap.min.css',
348        array(),
349        '5.3.0'
350    );
351
352    // Font Awesome CSS
353    wp_enqueue_style(
354        'fontawesome-css',
355        get_template_directory_uri() . '/assets/css/all.min.css',
356        array(),
357        '6.4.2'
358    );
359
360    // Slick Carousel CSS
361    wp_enqueue_style(
362        'slick-css',
363        get_template_directory_uri() . '/assets/css/slick.min.css',
364        array(),
365        '1.8.1'
366    );
367
368    // Main Theme Style
369    wp_enqueue_style(
370        'theme-style',
371        get_stylesheet_uri(),
372        array('bootstrap-css', 'fontawesome-css', 'slick-css'),
373        wp_get_theme()->get('Version')
374    );
375
376    // jQuery (WordPress built-in)
377    wp_enqueue_script('jquery');
378
379    // Bootstrap JS
380    wp_enqueue_script(
381        'bootstrap-js',
382        get_template_directory_uri() . '/assets/js/bootstrap.bundle.min.js',
383        array('jquery'),
384        '5.3.0',
385        true
386    );
387
388    // Slick JS
389    wp_enqueue_script(
390        'slick-js',
391        get_template_directory_uri() . '/assets/js/slick.min.js',
392        array('jquery'),
393        '1.8.1',
394        true
395    );
396}
397add_action('wp_enqueue_scripts', 'metawrite_enqueue_local_scripts');
398/* ==========================================================
399   //All css js and fonts enqueue style End here
400============================================================= */
401/* ==========================================================
402   //Customizer template register start here
403============================================================= */
404require get_template_directory() . '/inc/customizer/sidebar-banner-options.php';
405require get_template_directory() . '/inc/customizer/footer-logo.php';
406require get_template_directory() . '/inc/customizer/company-logos.php';
407require get_template_directory() . '/inc/customizer/customizer-contact.php';
408require get_template_directory() . '/inc/customizer/footer-newsletter.php';
409require get_template_directory() . '/inc/customizer/header-variation.php';
410require get_template_directory() . '/inc/customizer/customizer-featured.php';
411
412/* ==========================================================
413   //Customizer template register End here
414============================================================= */
415
416// Enqueue scripts and localize AJAX
417add_action('wp_enqueue_scripts', 'recently_posts_scripts');
418function recently_posts_scripts() {
419    wp_enqueue_script('recently-posts-js', get_template_directory_uri() . '/js/recently-posts.js', array('jquery'), '1.0', true);
420
421    wp_localize_script('recently-posts-js', 'recentlyPosts', array(
422        'ajaxurl' => admin_url('admin-ajax.php'),
423        'nonce' => wp_create_nonce('recently_posts_nonce')
424    ));
425}
426
427/* ===============================================
428//Includes files start here
429==================================================*/
430require get_template_directory() . '/inc/brevo-integration.php';
431require_once get_template_directory() . '/inc/demo-import-popup.php';
432require_once get_template_directory() . '/inc/language-translator.php';
433/* ===============================================
434//Includes files end here
435==================================================*/
436
437/* ==========================================================
438   // Register All recently post start here
439============================================================= */
440add_action('wp_ajax_load_recently_posts', 'load_recently_posts_callback');
441add_action('wp_ajax_nopriv_load_recently_posts', 'load_recently_posts_callback');
442
443function load_recently_posts_callback() {
444    while (ob_get_level()) {
445        ob_end_clean();
446    }
447    ob_start();
448
449    check_ajax_referer('recently_posts_nonce', 'security');
450
451    $tag_slug          = isset($_POST['tag_slug']) ? sanitize_text_field($_POST['tag_slug']) : '';
452    $latest_news_cat_id = get_cat_ID('Latest News');
453
454    $args = array(
455        'post_type'        => 'post',
456        'posts_per_page'   => -1,
457        'post_status'      => 'publish',
458        'order'            => 'ASC',
459        'orderby'          => 'date',
460        'category__not_in' => array($latest_news_cat_id),
461    );
462
463    if (!empty($tag_slug)) {
464        $args['tag'] = $tag_slug;
465    }
466
467    $query = new WP_Query($args);
468
469    if ($query->have_posts()) {
470        ob_start();
471
472        while ($query->have_posts()) : $query->the_post();
473
474            $post_id     = get_the_ID();
475            $post_image  = get_the_post_thumbnail_url($post_id, 'large') ?: 'https://via.placeholder.com/600x400?text=No+Image';
476            $author_id   = get_the_author_meta('ID');
477            $author_name = get_the_author();
478            $post_date   = get_the_date('d F Y');
479            $post_time   = get_the_time('h:i A');
480            $author_bio  = get_the_author_meta('description');
481            $tags        = get_the_tags();
482            $tag_names   = $tags ? implode(', ', wp_list_pluck($tags, 'name')) : '';
483            $content     = get_the_content();
484            $excerpt     = wp_trim_words($content, 15, '');
485            ?>
486
487            <div class="mw-recently-blog-card">
488                       <a href="<?php echo esc_url( get_permalink() ); ?>">
489                <img src="<?php echo esc_url( $post_image ); ?>"
490                    class="mw-recently-img"
491                    alt="<?php echo esc_attr( get_the_title() ); ?>" />
492            </a>
493
494                <div class="mw-recently-blog-details">
495                   <span class="mw-recently-tag">
496    <?php
497    $tags = get_the_tags();
498    if ($tags) {
499        foreach ($tags as $tag) {
500            $tag_link = get_tag_link($tag->term_id);
501            echo '<a href="' . esc_url($tag_link) . '" class="post-title-tags-link">' . esc_html($tag->name) . '</a> ';
502        }
503    }
504    ?>
505</span>
506
507        <div class="mw-post-descriptions">
508        <a href="<?php the_permalink(); ?>" class="post-title-link">
509             <?php
510                        $title = get_the_title();
511                        $words = explode(' ', $title);
512                        $limited_words = array_slice($words, 0, 10);
513                        $processed_words = array_map(function($word) {
514                            return (mb_strlen($word) > 20) ? mb_substr($word, 0, 20) : $word;
515                        }, $limited_words);
516                        echo implode(' ', $processed_words);
517                    ?>
518                </a>
519            </div>
520                <p class="mw-recently-author-details">
521                           <strong>
522                                <a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>"
523                                class="text-decoration-none">
524
525                                    <?php echo get_avatar(
526                                        $author_id,
527                                        40,
528                                        '',
529                                        esc_attr(get_the_author()),
530                                        ['class' => 'author-img rounded-img']
531                                    ); ?>
532
533                                    <span class="mw-authors-icons">
534                                        <?php the_author(); ?>
535                                    </span>
536                                </a>
537                            </strong>
538
539                        <strong class="popular-post-icon">|
540                            <img src="<?php echo esc_url(get_stylesheet_directory_uri()); ?>/assets/Author Icon Container.svg"
541                                 class="read-clander-img"
542                                 alt="Author icon" />
543                            <i class="bi bi-calendar" aria-hidden="true"></i>
544                            <span class="visually-hidden">Published on </span>
545                            <?php echo esc_html($post_date); ?>
546                        </strong>
547
548                        <strong class="popular-post-icon">|
549                            <img src="<?php echo esc_url(get_stylesheet_directory_uri()); ?>/assets/Read Time Icon Container.svg"
550                                 class="read-time-img"
551                                 alt="Read time icon" />
552                            <i class="bi bi-clock" aria-hidden="true"></i>
553                            <span class="visually-hidden">Published at </span>
554                            <?php echo esc_html($post_time); ?>
555                        </strong>
556                    </p>
557                    <p>
558                        <?php echo esc_html($excerpt); ?>
559                        <a href="<?php the_permalink(); ?>" class="text-decoration-none">Read More</a>
560                    </p>
561                </div>
562            </div>
563
564            <?php
565        endwhile;
566
567        wp_reset_postdata();
568        $output = ob_get_clean();
569        wp_send_json_success($output);
570
571    } else {
572        wp_send_json_error('<p>No posts found for this tag.</p>');
573    }
574    wp_die();
575}
576
577/* ==========================================================
578// Register All recently post End here
579============================================================= */
580/* ==========================================================
581// Register All popular post start here
582============================================================= */
583add_action('wp_ajax_load_popular_posts', 'load_popular_posts_callback');
584add_action('wp_ajax_nopriv_load_popular_posts', 'load_popular_posts_callback');
585
586function load_popular_posts_callback() {
587    $popular_args = [
588        'post_type'      => 'post',
589        'posts_per_page' => 2,
590        'post_status'    => 'publish',
591        'orderby'        => 'comment_count',
592        'order'          => 'DESC',
593        'category_name'  => 'popular',
594    ];
595
596    $popular_query = new WP_Query($popular_args);
597
598    ob_start();
599
600    if ($popular_query->have_posts()) :
601        while ($popular_query->have_posts()) : $popular_query->the_post();
602            $author_id   = get_the_author_meta('ID');
603            $author_img  = get_avatar_url($author_id);
604            $read_time   = function_exists('estimated_read_time') ? estimated_read_time(get_the_content()) : '';
605            $cats        = get_the_category();
606            $cat_name    = !empty($cats) ? $cats[0]->name : '';
607            $post_time   = get_the_time('h:i A');
608            $post_date   = get_the_date('d F Y');
609            $tags        = get_the_tags();
610            $tag_names   = $tags ? implode(', ', wp_list_pluck($tags, 'name')) : '';
611            $content     = get_the_content();
612            $excerpt     = wp_trim_words($content, 11, '');
613            ?>
614
615            <div class="mt-3 popular-section">
616
617    <!-- Post Tags -->
618            <?php if ( $tags ) : ?>
619                <div class="mw-post-heading-tag">
620                    <?php foreach ( $tags as $tag ) : ?>
621                        <a href="<?php echo esc_url( get_tag_link( $tag->term_id ) ); ?>"
622                        class="post-title-tags-link">
623                            <?php echo esc_html( $tag->name ); ?>
624                        </a>
625                    <?php endforeach; ?>
626                </div>
627            <?php endif; ?>
628
629
630    <!-- Post Title -->
631                <div class="mw-popular-description">
632                    <a href="<?php the_permalink(); ?>" class="post-title-links mw-popular-description" style="font-weight: 500;">
633                        <?php echo wp_trim_words(get_the_title(), 7, ' '); ?>
634                    </a>
635                </div>
636
637    <!-- Author Info and Meta -->
638                <p class="mw-authors-icons">
639                     <strong>
640                        <a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>"
641                         class="text-decoration-none">
642                                    <?php echo get_avatar(
643                                        $author_id,
644                                        40,
645                                        '',
646                                        esc_attr(get_the_author()),
647                                        ['class' => 'author-img rounded-img']
648                                    ); ?>
649
650                                    <span class="mw-authors-icons">
651                                        <?php the_author(); ?>
652                                    </span>
653                                </a>
654                            </strong>
655
656            <strong class="popular-post-icons">|
657                <img src="<?php echo esc_url(get_stylesheet_directory_uri()); ?>/assets/Author Icon Container.svg"
658                    class="read-clander-img"
659                    alt="Author icon" />
660                <?php echo esc_html($post_date); ?>
661            </strong>
662
663            <strong class="popular-post-icons">|
664                <img src="<?php echo esc_url(get_stylesheet_directory_uri()); ?>/assets/Read Time Icon Container.svg"
665                    class="read-time-img"
666                    alt="Read time icon" />
667                <?php echo esc_html($post_time); ?>
668            </strong>
669
670                </p>
671
672            <!-- Post Excerpt -->
673                <p class="mw-sidebar-text">
674                    <?php echo esc_html($excerpt); ?>
675                      <a href="<?php the_permalink(); ?>" style="text-decoration: none; color: #0065cbff;">Read more</a>
676                </p>
677            </div>
678
679            <?php
680        endwhile;
681    else :
682        echo '<p>No popular posts found.</p>';
683    endif;
684
685    wp_reset_postdata();
686    echo ob_get_clean();
687    wp_die();
688}
689
690/* ==========================================================
691// Register All popular post End here
692============================================================= */
693function enqueue_metawrite_scripts() {
694    wp_enqueue_script('my-custom-js', get_template_directory_uri() . '/assets/js/custom.js', array(), false, true);
695    wp_localize_script('my-custom-js', 'mw_ajax_obj', array(
696        'ajax_url' => admin_url('admin-ajax.php')
697    ));
698}
699add_action('wp_enqueue_scripts', 'enqueue_metawrite_scripts');
700
701/* ==========================================================
702//Add editor support start here
703============================================================= */
704add_theme_support('wp-block-styles');
705add_theme_support('align-wide');
706add_theme_support('responsive-embeds');
707add_editor_style('editor-style.css');
708
709/**
710 * IMPORTANT: register_block_pattern must run at/after `init` (not in global scope),
711 * otherwise translation strings (__()) trigger the "just in time" notice.
712 */
713function meta_write_register_block_patterns() {
714    if ( function_exists( 'register_block_pattern' ) ) {
715        register_block_pattern(
716            'meta-write/hero-section',
717            array(
718                'title'       => __( 'Hero Section', 'meta-write' ),
719                'description' => __( 'A simple hero block with a title and paragraph.', 'meta-write' ),
720                'content'     => '<!-- wp:heading {"level":1} --><h1>Welcome to Meta Write</h1><!-- /wp:heading -->',
721            )
722        );
723    }
724}
725add_action( 'init', 'meta_write_register_block_patterns' );
726/* ==========================================================
727//Add editor support End here
728============================================================= */
729
730function meta_write_register_custom_block_styles() {
731    if ( function_exists( 'register_block_style' ) ) {
732        register_block_style(
733            'core/button',
734            array(
735                'name'  => 'rounded-outline',
736                'label' => __( 'Rounded Outline', 'meta-write' ),
737                'style_handle' => 'meta-write-block-styles'
738            )
739        );
740    }
741}
742add_action( 'init', 'meta_write_register_custom_block_styles' );
743
744/* ==========================================================
745//Add minify css and js directory template start here
746============================================================= */
747function metawrite_enqueue_assets() {
748    wp_enqueue_style('metawrite-style', get_template_directory_uri() . '/dist/style.css', [], wp_get_theme()->get('Version'));
749    wp_enqueue_script('metawrite-script', get_template_directory_uri() . '/dist/bundle.js', [], wp_get_theme()->get('Version'), true);
750}
751add_action('wp_enqueue_scripts', 'metawrite_enqueue_assets');
752
753/* ==========================================================
754//Add minify css and js directory template End here
755============================================================= */
756
757/* ==========================================================
758//Add footer menu start here
759============================================================= */
760function register_footer_menus() {
761    register_nav_menus([
762        'footer_blog_menu'   => __('Footer Blog Menu', 'meta-write'),
763        'footer_quick_links' => __('Footer Quick Links Menu', 'meta-write'),
764    ]);
765}
766add_action('after_setup_theme', 'register_footer_menus');
767
768/**
769 * Register navigation menus.
770 */
771function meta_write_register_menus() {
772    register_nav_menus([
773        'secondary' => __('Contact Menu', 'meta-write'),
774    ]);
775}
776add_action('after_setup_theme', 'meta_write_register_menus');
777
778/* ==========================================================
779//Add footer menu End here
780============================================================= */
781
782/* ==========================================================
783//Add sidebar widget start here
784============================================================= */
785/**
786 * Removed duplicate global register_sidebar() that caused early translation calls.
787 * Sidebar is already registered in meta_write_widgets_init() on widgets_init.
788 */
789/* ==========================================================
790//Add sidebar widget end here
791============================================================= */
792
793/* ==========================================================
794//Add Svg  logo start here
795============================================================= */
796function meta_write_enable_svg() {
797
798    $filter_name = 'upload' . '_mimes';
799    add_filter( $filter_name, function( $mimes ) {
800        $mimes['svg'] = 'image/svg+xml';
801        return $mimes;
802    });
803}
804add_action( 'init', 'meta_write_enable_svg' );
805/* ===============================================
806//Add Svg logo End here
807==================================================*/
808/* ===============================================
809//Customizer sidebar start here
810==================================================*/
811function meta_write_sidebar_banner_customizer_css() {
812    ?>
813    <style type="text/css">
814        .mw-sidebar-banner {
815            background-color: <?php echo esc_attr( get_theme_mod('meta_write_sidebar_banner_bg_color', '#f9f9f9') ); ?>;
816            color: <?php echo esc_attr( get_theme_mod('meta_write_sidebar_banner_text_color', '#333333') ); ?>;
817        }
818        .mw-sidebar-banner h6,
819        .mw-sidebar-banner h5,
820        .mw-sidebar-banner p {
821            color: <?php echo esc_attr( get_theme_mod('meta_write_sidebar_banner_text_color', '#333333') ); ?>;
822        }
823        .mw-sidebar-banner .btn-custom {
824            background-color: <?php echo esc_attr( get_theme_mod('meta_write_sidebar_banner_btn_bg_color', '#0073e6') ); ?>;
825            color: <?php echo esc_attr( get_theme_mod('meta_write_sidebar_banner_btn_text_color', '#ffffff') ); ?>;
826        }
827    </style>
828    <?php
829}
830 add_action( 'wp_head', 'meta_write_sidebar_banner_customizer_css' );
831
832/* ===============================================
833//Customizer sidebar end here
834==================================================*/
835
836/* ===============================================
837// Gutenberg Compatibility (Backend + Frontend)
838==================================================*/
839
840function meta_write_gutenberg_support() {
841
842    // Enable Gutenberg core supports
843    add_theme_support( 'align-wide' );
844    add_theme_support( 'wp-block-styles' );
845    add_theme_support( 'responsive-embeds' );
846    add_theme_support( 'editor-styles' );
847
848    // Load backend (editor) style
849    add_editor_style( 'assets/css/gutenberg-shared.css' );
850
851    // Define theme color palette
852    add_theme_support( 'editor-color-palette', [
853        [ 'name' => __( 'Primary', 'meta-write' ), 'slug' => 'primary', 'color' => '#0274be' ],
854        [ 'name' => __( 'Accent', 'meta-write' ), 'slug' => 'accent', 'color' => '#ed502e' ],
855        [ 'name' => __( 'Dark Gray', 'meta-write' ), 'slug' => 'dark-gray', 'color' => '#333333' ],
856        [ 'name' => __( 'Light Gray', 'meta-write' ), 'slug' => 'light-gray', 'color' => '#f5f5f5' ],
857        [ 'name' => __( 'White', 'meta-write' ), 'slug' => 'white', 'color' => '#ffffff' ],
858    ]);
859
860    // Font sizes
861    add_theme_support( 'editor-font-sizes', [
862        [ 'name' => __( 'Small', 'meta-write' ), 'size' => 14, 'slug' => 'small' ],
863        [ 'name' => __( 'Normal', 'meta-write' ), 'size' => 16, 'slug' => 'normal' ],
864        [ 'name' => __( 'Large', 'meta-write' ), 'size' => 32, 'slug' => 'large' ],
865        [ 'name' => __( 'Huge', 'meta-write' ), 'size' => 48, 'slug' => 'huge' ],
866    ]);
867}
868add_action( 'after_setup_theme', 'meta_write_gutenberg_support' );
869
870/* ===============================================
871// Styles on Frontend
872==================================================*/
873
874function meta_write_load_gutenberg_frontend_styles() {
875    wp_enqueue_style(
876        'meta-write-gutenberg-shared',
877        get_stylesheet_directory_uri() . '/assets/css/gutenberg-shared.css',
878        array('wp-block-library'),
879        wp_get_theme()->get('Version')
880    );
881}
882add_action('wp_enqueue_scripts', 'meta_write_load_gutenberg_frontend_styles');
Note: See TracBrowser for help on using the repository browser.