Max Yudin
  • Member for 10 years
  • Last seen this week
Make custom column sortable
23 votes

Make sure to change MY_POST_TYPE, MY_CUSTOM_COLUMN and MY_META_KEY to the actual values. First, add your custom column. Unset the date and set it again to keep it in the last column. You can skip ...

View answer
Is moving wp-config outside the web root really beneficial?
16 votes

Definitely YES. When you move wp-config.php outside public directory you protect it from reading using browser when php handler gets maliciously (or accidentally!) changed. Reading your DB login/...

View answer
How do you add custom color swatches to all WYSIWYG editors?
Accepted answer
15 votes

Click on the Custom... text and the color picker will pop up. Pick the color of your choice and press OK. Chosen color will appear as a custom swatch for later use. Note! The solution above is not a ...

View answer
How to add a class to ul tags created by the WordPress editor Tinymce?
Accepted answer
14 votes

It's always a good idea to look at Wordpress Codex before asking. TinyMCE Custom Styles <?php // Insert 'styleselect' into the $buttons array function my_mce_buttons_2( $buttons ) { ...

View answer
Remove rel=shortlink from HTTP header
Accepted answer
12 votes

<?php add_filter('after_setup_theme', 'remove_redundant_shortlink'); function remove_redundant_shortlink() { // remove HTML meta tag // <link rel='shortlink' href='http://example.com/?p=...

View answer
Show content after the first and second paragraph
Accepted answer
9 votes

My way to do this (see update below): function addParagraphs($content) { // you can add as many as you want: $additions = array( '<p>After 1st paragraph</p>', '<...

View answer
is_page_template & is_page in functions.php not working
Accepted answer
8 votes

Use wp_enqueue_scripts instead on init. This will ensure you the template is already loaded. add_action('wp_enqueue_scripts', 'maps_scripts'); Or you try to check the template using ...

View answer
the_title filter applying to menu items
Accepted answer
7 votes

Use in_the_loop() conditional tag to make sure you are modifying the title inside the Loop and to prevent the hook changing titles somewhere else: function customize_wishlist_title( $title ){ $...

View answer
Disable permalink on custom post type
Accepted answer
7 votes

<?php add_filter('get_sample_permalink_html', 'my_hide_permalinks'); function my_hide_permalinks($in){ global $post; if($post->post_type == 'my_post_type') $...

View answer
Multiple category RSS feeds
Accepted answer
6 votes

http://www.example.com/category/cat1,cat2/feed will include posts belonging to cat1 OR cat2, while http://www.example.com/category/cat1/category/cat2/feed will include posts belonging to both cat1 ...

View answer
enqueue script on custom post type archive page
Accepted answer
6 votes

You can save your time and server load by not using wp_register_script and wp_register_style when you don't need them definitely. wp_enqueue_style and wp_enqueue_script do the same job themselves when ...

View answer
how to get recent registered author id?
Accepted answer
6 votes

I don't think you need any SQL queries. <?php $args = array( 'role' => 'author', // authors only 'orderby' => 'registered', // registered date 'order' => '...

View answer
how to change default icon of custom plugin?
6 votes

add_menu_page() has the $icon_url parameter. Icon size should be 16x16px. add_menu_page( __( 'Poll', 'example_textdomain' ), __( 'Poll', 'example_textdomain' ), 'manage_options', '...

View answer
wp_list_pages shortcode jumps above previous content
Accepted answer
5 votes

That's because your list is printed immediately. wp_list_pages() has the echo parameter, which is true by default. Make it false like here: <?php function roofspan_product_childpages() { $...

View answer
Create ul list in Custom Meta Box?
5 votes

You can add your information in regular metabox textarea and separate prospective list items with new line. Then just format it as list in your template: <?php $list_items = get_post_meta($post-&...

View answer
check if a file in a plugin folder exists from a locale installation
Accepted answer
5 votes

Use if( file_exists(plugin_dir_path(__FILE__) . 'myfile.ext') ) {} instead of if( file_exists( plugins_url( "myfile.ext", __FILE__ ) ) ) {} See plugin_dir_path in the Codex.

View answer
_n() Single and Plural for search results?
Accepted answer
5 votes

Instead of using 'if' loop it's better to use special function: <?php echo _n( 'article', 'articles', $count, 'my-plugin-domain' ); ?> http://codex.wordpress.org/Function_Reference/_n

View answer
Custom data-id wp_enqueue_script
Accepted answer
4 votes

script_loader_tag filter was introduced in WordPress 4.1: <?php add_filter( 'script_loader_tag', 'my_script_attributes', 10, 3 ); function my_script_attributes( $tag, $handle, $src ) { // ...

View answer
Hook on trash post
4 votes

Run your function when post status changes from any of publish, draft or future to trash. <?php function my_function() { global $post; if('my_post_type' == $post->post_type) { //...

View answer
Overriding WooCommerce CSS?
4 votes

You can change the CSS loading order. Find the place where WooCommerce enqueues it's CSS and keep in mind it's $handle (name). Search for wp_enqueue_style. Then go to theme's functions.php and find ...

View answer
Filter results with custom field values and dropdown
Accepted answer
4 votes

Edited according to first comments and Pastebin code: <?php /* You can also leave 'action' blank: action="" */ ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> &...

View answer
Hide WYSIWYG editor on certain templates
Accepted answer
3 votes

I hope I understood your question right. The following code will remove the editor from the pages using particular templates: <?php function wpse242371_remove_editor_from_some_pages() { ...

View answer
Pull Two Different Post Types into Different HTML Containers on the Same Page
Accepted answer
3 votes

Updated 10 hours later: enriched with alternative solution and complemented with comments. <?php /* ******* Built-in post type "Post" ******* */ $arguments_for_posts = array( 'numberposts' =&...

View answer
How to get Post Type from the functions.php file
Accepted answer
3 votes

You have to create the function and call it when post ID is already set. Otherwise it will be empty. E.g. wp_head meets this requirement, init is too early. function my_selective_wpautop() { ...

View answer
Download file using cURL into wp-includes/uploads
3 votes

There is special wp_upload_bits() function to upload the content to the 'uploads' directory. Also, there is no such directory as /wp-includes/upload/. The code was not tested! <?php $video_id = '...

View answer
How to get WordPress Username in Array format
3 votes

Look at get_users() function. <?php $users = get_users(); foreach( $users as $user ) { // get user names from the object and add them to the array $get_arr_user[] = $user->...

View answer
Query for custom posts with a specific tag slug
3 votes

Since tag is a taxonomy of a custom_post post type, the query could look like this: <?php $args = array( 'post_type' => 'custom_post', 'tax_query' => array( array( ...

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

Don't use single quotes with escape sequences like \r, \n and so on. Use double quotes: $a = 'Hello, ' . "\n"; $b = "Good Bye, \n"; See Double quoted strings in PHP.

View answer
How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
3 votes

<?php // get all terms of the `bank` taxonomy $banks = get_terms( array( 'taxonomy' => 'bank', // more arguments can be used, see (1) below the code ) ); // look through ...

View answer
get_edit_post_link() not working as expected when passed id in plugin
Accepted answer
3 votes

According to the get_edit_post_link() function source this can happen in following conditions: there is no such post; there is no such post type; you don't have enough permissions to edit the post; ...

View answer
1
2 3 4 5
9