majick
  • Member for 6 years, 6 months
  • Last seen this week
Ignoring initial articles (like 'a', 'an' or 'the') when sorting queries?
12 votes

An easier way may be to go through and change the permalink slug on those posts that need it (under the title on the post writing screen) and then just use that for ordering instead of the title. ie....

View answer
Sending multipart (text/html) emails via wp_mail() will likely get your domain banned
10 votes

TLDR, the simple solution is: add_action('phpmailer_init','wp_mail_set_text_body'); function wp_mail_set_text_body($phpmailer) { if (empty($phpmailer->AltBody)) {$phpmailer->AltBody = ...

View answer
Annoying "JQMIGRATE: Migrate is..." in console after update to WordPress 4.5
10 votes

You could change the log message text to blank in jquery-migrate.min.js but this will not be preserved on core update. The alternative is to add passthrough/filter function copy of console.log to ...

View answer
How to change the location of admin notice in html without using Javascript?
Accepted answer
9 votes

I found out by accident recently that all the notices will be moved to after the first <h2> tag on the page inside a <div class="wrap">. This gives you some slight control in that, for ...

View answer
How to log plugin errors to plugin error_log file
Accepted answer
8 votes

By setting the second argument to 3 for error_log: $pluginlog = plugin_dir_path(__FILE__).'debug.log'; $message = 'SOME ERROR'.PHP_EOL; error_log($message, 3, $pluginlog); http://php.net/manual/en/...

View answer
responsive.css in the Wordpress should be prioritized
Accepted answer
7 votes

If you want to make sure the second stylesheet loads after the first, you can use the third argument of wp_enqueue_style to set a dependency, eg: wp_enqueue_style( 'styles', THEMEROOT . '/css/style....

View answer
Exclude filter on front page
Accepted answer
5 votes

You can just remove the filter before calling the_excerpt and then add it back afterwards... remove_filter('excerpt_more','new_excerpt_more'); the_excerpt(); add_filter('excerpt_more', '...

View answer
Best Practice for Referencing the Plugin Directory
5 votes

You can use: plugin_dir_path(__FILE__); Which as is just a wrapper function anyway for: trailingslashit(dirname(__FILE__));

View answer
Refactor create_function
4 votes

There is an inbuilt function for returning null: __return_null. So you can replace create_function('$a', 'return null;'); with just '__return_null' (note the quotes) as it seems $a is not used ...

View answer
How To Have Two Gutenberg Editors On One Post?
Accepted answer
4 votes

You could add some kind of separator (a separator block?) in Gutenberg, then filter the_content() to check for the separator to display each half, by setting a switch on the first half and detecting ...

View answer
Trigger Javascript on Gutenberg (Block Editor) Save
Accepted answer
4 votes

Okay, so way way more hacky solution than I wanted, but got it working... Here is a slightly simplified and abstracted way of doing it from my code, in case anyone ever needs to do the same (as I'm ...

View answer
Want to enforce the visitor to load the new version of your stylesheets and scripts
4 votes

Sounds like you are talking about cachebusting. Changing the querystring makes the browser interpret the URL as a new resource. Unless you want to change the entire filename there really isn't a ...

View answer
What is pclzip.lib.php file that wordfence think it's a malicious code
4 votes

Sounds like it is definitely malicious code masquerading as a legitimate file. In WordPress core the legitimate file lives as /wp-admin/includes/class-pclzip.php so there is no need for this to be ...

View answer
Custom attribute for the title tag with wp_title()
Accepted answer
4 votes

Since all _wp_render_title_tag does is check for title-tag theme support and wrap in <title> tags, there is really no reason why your existing implementation "shall not pass", since the proper ...

View answer
how to include other plugins css files in a shortcode?
Accepted answer
4 votes

I think you could get around this by pre-running the shortcodes on the page by applying the content filters before the header is output. This should allow any internal shortcodes run inside the ...

View answer
How to use prepare to query with variables
Accepted answer
4 votes

Try adding the single quotes back around the %s: $countthem = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM wp_cmapg WHERE lang='%s'", $lang) );

View answer
Create category post shortcode
Accepted answer
3 votes

Needs a complete rewrite... add_shortcode( 'categorypost', 'cat_post' ); function cat_post( $atts ) { // attributes for shortcode if ( isset( $atts['cat'] ) ) {$cats = $atts['cat'];} else {...

View answer
Convert this textarea to rich html format via wp_editor
3 votes

You basically have two options, using PHP or Javascript. With PHP you would use the wp_editor function to output the textarea for you, and with Javascript you would convert the existing textarea ...

View answer
Easy code troubleshooting in wordpress
3 votes

Unfortunately there isn't really a standard developer logging API in WordPress. If you want to output your own data to a debug file (to prevent "headers already sent" errors) then you can simply use ...

View answer
How to add line breaks to $email['body'] when using auto_core_update_email hook
3 votes

Apart from using "\n", you could also use PHP's end of line constant: PHP_EOL $email['body'] = 'Hello,%0D%0A' . PHP_EOL . 'Lorem ipsum.%0D%0A' . PHP_EOL . 'Many thanks,%0D%0A' . PHP_EOL . '...

View answer
"wp_enqueue_style();" don't load new edited style
Accepted answer
3 votes

Another solution is to use filemtime for the cachebusting, so that the last modified timestamp is used as the querystring variable. This has the advantage that of still using the browser cache, and ...

View answer
How to auto login user again after change user_login
Accepted answer
3 votes

I found when attempting similar I needed to clear the user cache to get the relogin to work (after much frustrating testing!): wp_cache_delete($user_id, 'users'); wp_cache_delete($old_user_login, '...

View answer
Organize functions.php
Accepted answer
3 votes

Doing this simply won't make a significant performance difference, instead organize your customizations with clear headings so you can find and edit things faster later... in other words, organize for ...

View answer
Variable not being passed into WordPress loop
Accepted answer
3 votes

If $my_share echoes as "5171,5167,5165" then it is a string not an array... In other words array($string) does not equal array(integer,integer,integer) even if $string equals "integer,integer,integer"...

View answer
Meta_Query as a way how to setup CPT permalinks - is it a good thing?
3 votes

Since it is a performance question, you might be able to avoid using meta keys at all by storing/getting that data another way and not having to set a separate meta field to match with... a. You ...

View answer
How do I call wp_mail from HTML?
3 votes

First the way to do this is with a form using the post method, it is slightly easier to understand: <!-- form with AJAX action and iframe target --> <form method="post" action="<?php echo ...

View answer
How to show page content in feed?
3 votes

As mentioned by @Sumit, you need to turn off the comments feed for a page (which I find really strange since by default comments are off on pages?) ... this is what I ended up with (allowing for ...

View answer
How to update user role without logout
Accepted answer
3 votes

I think you are on the right track, wp_cache_delete was what finally helped me get an auto-signup with auto-login plugin working... I have this from there: wp_cache_delete($current_user->ID, '...

View answer
Plugin base URL
Accepted answer
3 votes

I think you are looking for plugin_dir_url: $url = plugin_dir_url(__FILE__); $imageurl = $url.'images/someimage.png'; EDIT: Sorry I misread the question... that is only an answer to the linked ...

View answer
Passing variable from child theme to parent theme
Accepted answer
3 votes

Stick to filtering one value at a time to keep it simple, and add filters for the colors to be used by the child theme: add_filter( 'post_thumbnail_html', 'map_thumbnail'); function map_thumbnail($...

View answer
1
2 3 4 5
10