Tag Info

Hot answers tagged

3

You have a syntax-ish error, or a spelling one. There is a space after "taxonomy" in your tax_query array. If that were the sum of it I'd have just posted a comment, but additionally that $query->tax_query->queries[] = $workspace_taxonomy_query; line is pointless. Nothing changes with or without it. Don't try to hack the array like that. Just use ...


3

The difference would be negligible. The the_content filter is fired regardless of whether you use it or not because WordPress uses it for other things. So the only thing that would be performance related would be the complexity of your filter function. But since you'd probably be doing the same level of complexity in a template or in the filter function, ...


3

Following code should do the trick. It takes the excerpt filter and returns the content instead. function wpse189347_excerpt( $excerpt ){ return get_the_content(); } add_filter( 'the_excerpt', 'wpse189347_excerpt', 10, 1 );


2

A page template might be more efficient. If you decide to use the filter, you should return the value: function str_load_table($content) { if(is_page('my-table')) { $my_content = 'pretend this is a table'; $content .= $my_content } return $content; }


2

Because the credit data is saved in the attachment's post meta, not the main post: $credit = get_post_meta( $post->ID /* Wrong ID! */, 'credit', true ); Instead you need to catch the ID of the inserted image: function attach_image_credit( $images ) { $return = $images[0]; // Get the image ID from the unique class added by insert to editor: ...


1

Try this. First check if the original string length is less than or equal to passed in length, and if so, we ignore the $after parameter : function the_titlesmall($before = '', $after = '', $echo = true, $length = false) { $title = get_the_title(); if( strlen($title) <= $length ) $after = ''; if ( $length && is_numeric($length) ...


1

As @bonger said, let your filters accept a second argument, which will be the instance of WP_Query that's executing the filter, and check it is indeed the main query for an event: function single_posts_fields( $sql, $wp_query ) { if ( $wp_query->is_main_query() && $wp_query->is_singular( 'event' ) ) { // Do your stuff } } ...


1

Almost exactly the same to brasofilo, my code below also accounts for different taxonomies and removes the checkbox for parent categories at the top level, only if they have children. This allows for other top level categories that are childless to still be selectable. I put this simple code my theme's functions.php file: class Category_Checklist { ...


1

The filter wp_title won't pass $id to your function. Drop the parameter and instead retrieve it with get_queried_object_id(): function dw_listing_title( $title ) { if ( is_singular() && $id = get_queried_object_id() ) { // Modify $title as required } return $title; }


1

Better solution if you want to disable this: use a plugin. Same code as from Christine's comments: https://wordpress.org/plugins/disable-emojis/ Same code that also fixes the smilies to be the older ones: https://wordpress.org/plugins/classic-smilies/ Source: Me, since I wrote that code in the first place. ...


1

Here's a slightly modified version of your code snippet: add_action( 'login_head', [ 'WPSE_Admin', 'plugin_setup' ] ); class WPSE_Admin { public static function plugin_setup() { add_filter( 'login_headerurl', [ 'WPSE_Admin', 'the_logo_url' ] ); } public function the_logo_url() { return get_bloginfo('url'); } } The ...


1

The reason is that you can register native PHP functions as callbacks. Passing more parameters to them then they expect will raise a warning. Imagine a filter that can pass 6 parameters and trim() as callback. PHP would now raise an error: Warning: Wrong parameter count for trim() in … Some custom callbacks might also change their behavior depending ...



Only top voted, non community-wiki answers of a minimum length are eligible