Articles of filters

Get the name of menu item with wp_nav_menu

Basically I’m customizing the menu through the options of wp_nav_menu(). Here is some of my code: function custom_novice_menu($args) { $args[‘container’] = false; $args[‘container_id’] = ‘my_primary_menu’; $args[‘link_before’] = ‘<div class=”topic-card”><div class=”topic-circle”></div><span></span><h3>’; $args[‘link_after’] = ‘</h3></div>’; return $args; } Essentially I want to get the name or ID of the current menu item. That way I can use […]

Secondary Navigation Menudisappeared When using wp_nav_menu_items

My Secondary Navigation Menu works fine until I use add_filter( ‘wp_nav_menu_items’) to add a login / logout button to my primary menu. Here is my code: add_filter( ‘wp_nav_menu_items’, ‘add_loginout_link’, 10, 2 ); function add_loginout_link( $items, $args ) { //Add item to primary menu if ($args->theme_location == ‘primary’) { //checks if user is logged in if […]

How include css class based on post ( in loop ) slug?

I’m using this function to retrieve body and single post classes from their slugs. add_filter( ‘post_class’, ‘fl_pages_bodyclass’ ); add_filter(‘body_class’,’fl_pages_bodyclass’); function fl_pages_bodyclass($classes) { if (is_page() || is_single() ) { // get page slug global $post; $slug = get_post( $post )->post_name; // add slug to $classes array $classes[] = $slug; // return the $classes array return $classes; […]

Print url to default featured image

I’m trying to setup a fallback image for featured image. The main problem I have is miss of filter for get_the_post_thumbnail_url(). I’m using this function to echo thumb url in many-many templates, because it is easy customizable. So, this is not a solution to make an if-condition for each usage. And even to set default […]

Filter categories of posts with checkboxes

Hello guys I’m trying to make simple filter options for my WordPress project. I want to do it with checkboxes. It looks like this: This is the code for checkboxes: <div class=”categories”> <?php $cat_count_web = get_category( ‘8’ ); $cat_count_marketing = get_category( ‘3’ ); $cat_count_uncatagorized = get_category( ‘1’); ?> <h3 title=”<?php echo $cat_count_web->count; ?>”> <?php echo […]

Remove Editor From Homepage

Im trying to remove the editor from the homepage using the following functions however I am struggling to achieve this? function hide_homepage_editor() { if ( is_admin() ) { if (is_front_page()) { remove_post_type_support(‘page’, ‘editor’); } } } add_action( ‘admin_init’, ‘hide_homepage_editor’ ); another try: function hide_homepage_editor() { if ( is_admin() ) { $post_id = 0; if(isset($_GET[‘post’])) $post_id […]

Add/remove CRON action depending on variable

I’ve hooked a function on to a CRON job called ‘job_manager_check_for_expired_jobs’, and I want it to run based on the value of a variable $create_sitemap. The value is true by default, but can be changed by a filter. The problem is that if I use the site and then then change the filter to be […]

Dropdown filter in custom posts

This is my snippet for drop-down filter in custom posts types: <?php function blog_restrict_manage_posts() { global $typenow; $taxonomy = ‘blog’; // Change this if( $typenow != “page” && $typenow != “post” ){ $filters = array($taxonomy); foreach ($filters as $tax_slug) { $tax_obj = get_taxonomy($tax_slug); $tax_name = $tax_obj->labels->name; $terms = get_terms($tax_slug); echo “<select name=’$tax_slug’ id=’$tax_slug’ class=’postform’>”; echo […]

get_posts() interrupt because of filter

There is a filter on my list-view page of my custom post type (works) add_action( ‘pre_get_posts’, array($this, ‘exclude_category’) ); public function exclude_category( $query){ if( is_admin() && isset( $_GET[‘cta_filter’]) && ! empty( $_GET[‘cta_filter’] ) ) { $term = sanitize_text_field( $_GET[‘cta_filter’] ); $query->tax_query->queries[] = array( ‘taxonomy’ => ‘cta_tax’, ‘field’ => ‘slug’, ‘terms’ => array( $term ), ‘operator’ […]

WordPress: Add custom add_filter for custom functions

I am coping with the scenario where I need to filter content of my custom function. My function is used for sending emails but I need to filter it just like wp_mail hook do. Here is my function: function koku_crm_send_sendgrid($sendgrid_api_key, $to, $subject, $text, $html) { $sendgrid = new \SendGrid($sendgrid_api_key); $mail = new KCSendGrid\Mail(); $from = […]