Articles of filters

Want to use wp_get_current_user() in query filter

I am using the WP “query” filter and in my function I want to use wp_get_current_user(). But I get a fatal error when I call it. Because the function isn’t loaded by WP yet. Is there a fix. ? public function __construct() { add_filter(‘query’, array($this,’my_func’), 10, 1); } function my_func($param){ $current_user = wp_get_current_user(); // Getting […]

How to have free shipping for WooCommerce Membership members

I was wondering if anyone had come up with a viable workaround to provide free shipping on products that are sold to members. The only possibility I can think of at the moment is to have two separate product offerings for each product – one for members and on for the public. But that would […]

How to add Shortcode (font awesome) in widget title?

I want to show font awesome icon (installed) on the left side of the WordPress widget title. I found this shortcode that should do the work. add_filter( ‘widget_title’, ‘do_shortcode’ ); add_shortcode( ‘icon’, ‘shortcode_fa’ ); function shortcode_fa($attr, $content ) { return ‘<i class=”fa fa-‘. $content . ‘”></i>’; } After adding this in functions.php, I should be […]

How to include add_filter() in a condition based on $post data

I’m writing a plugin that has a custom page for displaying user stats: has a custom permalink structure that takes the reader to the /user/ page and display the data for the ‘admin’ user. Meanwhile, should just return a list of all registered users. What I have done (that works) is have a […]

Include HTML (Bootstrap Modal Box) with a plugin into my header

I want to include some HTML, spezific a bootstrap modal box. This is my function with the HTML part: public function dmd_fav_modal_box() { $content = ‘<div class=”modal fade” id=”dmd_favorite_modal” tabindex=”-1″ role=”dialog” aria-labelledby=”dmd_favorite_modalLabel”> <div class=”modal-dialog” role=”document”> <div class=”modal-content”> <div class=”modal-header”> <button type=”button” class=”close” data-dismiss=”modal” aria-label=”Close”><span aria-hidden=”true”>&times;</span></button> </div> <div class=”modal-body”> <p>Test</p> </div> <!–div class=”modal-footer”> <button type=”button” class=”btn […]

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(); […]