Md Mehedi Hasan

get_option() || update_option || add_action() || add_filter() || remove_action || remove_filter()

category.php

<?php do_action("philosphy_category_page",single_cat_title('',false)); ?>
<?php get_header() ?>


    <!-- s-content
    ================================================== -->
    <section class="s-content">

        <div class="row narrow">
            <div class="col-full s-content__header" data-aos="fade-up">
                <?php echo apply_filters("philosophy_text","hello","wonderful", "world"); ?>
                <?php do_action("philosphy_before_category_title"); ?>
                <h2><?php _e("New Translatable Text",'philosophy'); ?></h2>
                <h2><?php printf(__("%s Hello World",'philosophy'),"Hi,"); ?></h2>
                <h1>
                    <?php single_cat_title(); ?>
                </h1>
                <?php do_action("philosphy_after_category_title"); ?>

                <?php do_action("philosphy_before_category_description"); ?>
                <p class="lead">
                    <?php echo category_description(); ?>
                </p>
                <?php do_action("philosphy_after_category_description"); ?>
            </div>
        </div>

        <div class="row masonry-wrap">
            <div class="masonry">

                <div class="grid-sizer"></div>

                <?php
                if ( ! have_posts() ):
                    ?>
                    <h5 class="text-center"><?php _e("There is no post in this category","philosophy"); ?></h5>
                <?php
                endif;
                ?>


                <?php
                while ( have_posts() ) {
                    the_post();
                    get_template_part( "template-parts/post-formats/post", get_post_format() );
                }
                ?>

            </div> <!-- end masonry -->
        </div> <!-- end masonry-wrap -->

        <div class="row">
            <div class="col-full">
                <nav class="pgn">
                    <?php philosophy_pagination(); ?>
                </nav>
            </div>
        </div>


    </section> <!-- s-content -->


<?php get_footer(); ?>

functions.php(apply_filters)

if (!function_exists("philosophy_pagination")) {
    function philosophy_pagination() {
        global $wp_query;
        $links = paginate_links(array(
            'current'  => max(1, get_query_var('paged')),
            'total'    => $wp_query->max_num_pages,
            'type'     => 'list',
            'mid_size' => apply_filters("philosophy_pagination_mid_size", 3),
        ));
        $links = str_replace("page-numbers", "pgn__num", $links);
        $links = str_replace("<ul class='pgn__num'>", "<ul>", $links);
        $links = str_replace("next pgn__num", "pgn__next", $links);
        $links = str_replace("prev pgn__num", "pgn__prev", $links);
        echo wp_kses_post($links);
    }
}

functions.php (action hook)

function beginning_category_page( $category_title ) {
	if ( "New" == $category_title ) {
		$visit_count = get_option( "category_new" );
		$visit_count = $visit_count ? $visit_count : 0;
		$visit_count ++;
		update_option( "category_new", $visit_count );
	}
}

add_action( "philosphy_category_page", "beginning_category_page" );

functions.php (filter hook)

function capital_text($text) {
    return strtoupper($text);
}
add_filter('philosophy_text', 'capital_text');

function philosophy_home_banner_class($class_name) {
    if (is_home()) {
        return $class_name;
    } else {
        return "";
    }
}

add_filter("philosophy_home_banner_class", "philosophy_home_banner_class");

function pagination_mid_size($size) {
    return 2;
}

add_filter("philosophy_pagination_mid_size", "pagination_mid_size");

function uppercase_text($param1, $param2, $param3) {
    return ucwords($param1) . " " . strtoupper($param2) . " " . ucwords($param3);
}

add_filter("philosophy_text", "uppercase_text", 10, 3);

functions.php (remove_action)

remove_action("philosphy_before_category_title", "category_before_title1");
remove_action("philosphy_before_category_title", "category_before_title2", 4);
remove_action("philosphy_before_category_title", "category_before_title3", 9);
remove_action("philosphy_after_category_title", "category_after_title");
remove_action("philosphy_after_category_description", "category_after_desc");
remove_filter("philosphy_filter_name", "function_name");