Articles of filters

Filter the blog's title without using global variables

The below code uses the bloginfo filter to add some CSS rules to my blog’s title and outputs it to the site header, without affecting the HTML head’s <title> tag. This solution was taken from here and it works very well (tested with Firefox in Ubuntu and with Android’s default browser). I like it because […]

Conditional does not work with add_filter

I want the conditional to be applied and that it is only displayed on pages, but it does not work, what is wrong? function luc_add_cutom_fields_to_content( $content ) { $custom_fields = get_post_custom(); $content .= “<div class=’cta-div’>”; if( isset( $custom_fields[‘luc_name’] ) ) { $content .= ‘<h3> ‘. $custom_fields[‘luc_name’][0] . ‘</h3>’; } if( isset( $custom_fields[‘luc_description’] ) ) { […]

Restrict displaying posts to the poster itself (in Back-end)

How can I filter posts in the Back-end so that logged in user sees only her/his own postings and not from others on the listings. My CPT declaration: $args = array( ‘labels’ => $labels, ‘description’ => ‘Test plugin.’, ‘public’ => true, ‘menu_position’ => 10, ‘supports’ => array(‘title’, ‘excerpt’, ‘comments’, ‘author’), ‘has_archive’ => false, ‘menu_icon’ => […]

Functions Filter Question

Why doesnt he input “$meinungen” ? add_filter(‘wpseo_set_title’, ‘wpseo_set_title_callback’); $meinungen = Test; function wpseo_set_title_callback($input) { if (is_single()) { return ”. $meinungen . ”. $input . ‘ ‘. $input . ”; } // return default return $input; }

Add custom link on the fly to nav menu

I need to add custom links, on the fly, to the navigation menu. I can add custom links to the first level of items (created via Appearance > Menus), but for some reason, I cannot add a custom link, child of another custom link create previously.. Here’s my code: function on_the_fly($items) { $menu_items = array(); […]

Redirect to woocommerce checkout after adding to cart – item already in cart

I have this code /* * Redirect to checkout after adding to cart */ function themeprefix_add_to_cart_redirect() { global $woocommerce; $checkout_url = $woocommerce->cart->get_checkout_url(); return $checkout_url; } add_filter(‘add_to_cart_redirect’, ‘themeprefix_add_to_cart_redirect’); The problem is clicking on a link like will not trigger the add_to_cart_redirect hook if there is something already in the cart. It thinks that there is […]

When to use add_action when registering/enqueuing scripts

When should you use add_action to enqueue or register a script, vs just using wp_register_script and/or wp_enqueue_script? In other words, both example 1 and example 2 below seem to accomplish the same thing when in functions.php, so why do so many resources say that example 1 is the correct way of loading scripts in WP? […]

Remove get_template_part() from custom theme

I am creating my own theme and was wondering if there is a way to remove get_template_part() when you’re on a specific page? For example: <?php if ( is_page(‘blog’) ) { [Remove]get_template_part(‘the’, ‘blog’); } ?>

Displaying content on posts page based on category

Typically if I wanted to have content based on what page someone was on I could do something like if (is_page(‘contact’)) { #code block here but what about if what want is based on the category of posts? like if the user wanted to filter event type or by state, for this example, lets say […]

add_filter : Passing an array instead of the callback function?

I was just reading through BuddyPress code because I want to develop a custom plugin on top of it. I encountered was something very peculiar that I haven’t seen before and cannot seem to find any material on. The following code is from a protected function under a class named as BP_Legacy // Filter BuddyPress […]