Tag Info

Hot answers tagged

6

Here's an example of the data returned from the wp_get_update_data() function: Array ( [counts] => Array ( [plugins] => 3 [themes] => 2 [wordpress] => 0 [translations] => 0 [total] => 5 ) [title] => 3 Plugin Updates, 2 Theme Updates ) So the number of ...


5

wp_get_update_data() returns an array in this format counts plugins themes wordpress translations total title So, if you want total count, you need to use it like this $updates = wp_get_update_data(); echo $updates['counts']['total'];


4

When using Ajax API, and you want to make the ajax callback available for non-logged users, you need to add 2 actions, "wp_ajax_{$action}" and "wp_ajax_nopriv_{$action}". Using only the first action, the callback will be called only for logged users, using only the second it will be called only for non-logged visitors. Try this: function check_username() ...


4

Note that if any script in the header at all needs jQuery then it will bump it to header, regardless if it's changed to be enqueued for footer. So while changing it to be queued for footer makes sense it rarely works out when a lot of script stuff is going on.


3

The last line tells WP to run this function on the pre_get_posts hook. That hook is the ideal place to modify the main query that will be run in order to build the page. In this case, exclude_featured_tag() checks whether WP is loading the home page, and whether it's about to call the main query for the page (as opposed to any other secondary queries being ...


3

This should hopefully do the trick: /** * Append the image categories to the current image class. * * @see http://wordpress.stackexchange.com/a/156576/26350 */ add_filter( 'get_image_tag_class', function( $class, $id, $align, $size ) { foreach( (array) get_the_category( $id ) as $cat ) { $class .= ' category-' . ...


3

Please change the type type : "GET", to type : "POST",


3

First, like many things in WordPress, it's not like someone decided "let's make this neat and convenient". It was more like someone slapped it together for something, then it got used more in admin, then it got used a lot in admin, then it became kind of practice to use it for non-admin as well. Or something along these lines. Second, it's not as much what ...


2

While Chinmoy's answer is correct I recommand you to use wp_send_json. When doing ajax this is really useful. It hanldes every essential part of the process including security. In real life you can use it like that : wp_send_json_success( $data);//successful requests wp_send_json_error( $data );// errors They return an array with $data encoded in json ...


2

You did not returning the default class if you are not viewing the contact page. Try this code once if(! function_exists( 'remove_hentry' )) { function remove_hentry( $classes ) { $classes[] = customTheme_layout_class(); if( is_page('contact') ) { $classes = array_diff( $classes, array( "hentry" ) ); } ...


1

It seems the problem was it wasn't recognizing it was a page in the first place and thus couldn't recognize if there was a template applied to it. Changed if (is_page_template('page-templates/page-nosidebar.php')) { to if (is_page() && !is_page_template('page-templates/page-nosidebar.php')) {


1

I think the path to the image is wrong, use get_stylesheet_directory_uri() to retrieve the style.css path. If this isn't it let me know and I will take a closer look. I just dug out an example which worked for me in the past: function my_login_logo() { ?> <style type="text/css"> body.login div#login h1 a { background-image: ...


1

you can use is_active_sidebar('your_sidebar_name or id') instead of is_dynamic_sidebar() to check whether required sidebar has widgets or not.It works for you in this case.


1

For reference, you may want to read the update_option documentation. The arguments you are passing are completely unrelated. However, your third technique is the closest, you have to update all the options in the the update_option call, not just the one option you want. This is because of how the plugin is storing it's options as an array rather than ...


1

Your code will be like this if( have_posts() ): while( have_posts()): the_post(); $txt_fld = get_post_meta( get_the_ID(), 'dbt_text', true ); $txt_fld2 = get_post_meta( get_the_ID(), 'dbt_text', true ); endwhile; endif; echo $txt_fld; echo $txt_fld2 like this way.


1

1.0.0? Really?! Anyway you could try the print_scripts_array filter: // Hack of wp_prototype_before_jquery() in "wp-includes/script-loader.php" function wpse157295_print_scripts_array( $js_array ) { if ( false === $jquery = array_search( 'jquery-core', $js_array, true ) ) // Now 'jquery-core', not 'jquery' return $js_array; $keys = array( ...


1

You simply need to run your code on a higher priority than what the parent theme is, the default on add_action function is 10 so you can use: function s157343_unregister_widgets() { unregister_widget( 'Chocolat_Widget_New_Entrys' ); } add_action( 'widgets_init', 's157343_unregister_widgets', 20 ); This will unregister that widget. Of course, you can ...


1

As it says right there is its inline documentation — the function is meant to only output the result "once per date". In typical chronological loop of posts it will "collapse" for posts made on same day. In less typical loop it might lead to pretty bizarre outputs. If you dig far and deep enough in version control history you might be able to dig up ...


1

For historical bloggy reasons, the_date in WordPress won't show the same date twice in a row. This is for grouping purposes. The fix is easy: Use the_time instead. It behaves exactly the same as the_date, but without the internal historical logic. Also no need to rewrite any complicated code, just change three characters. :) Note: the_time is missing the ...


1

You don't need to create additional functions, just re-use what you already have and tweak it a bit: function theme_add_bootstrap() { wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/third_party/bootstrap/css/bootstrap.min.css' ); wp_enqueue_script( 'bootstrap-js', get_template_directory_uri() . ...


1

bloginfo('url') should get you the URL for the installation. EDIT: I guess you could also use get_permalink()


1

First, you are confused. It is not the same "override a function" that remove a filter. Assuming that you want to remove a filter, I think that your code should be: function remove_html5_insert_image(){ remove_filter('image_send_to_editor','html5_insert_image', 10); } add_action('after_setup_theme','remove_html5_insert_image'); Note that the filter ...


1

Here's what I do to keep my RSS Templates together though depending on your version of PHP this may not work but it's pretty clean. You can add multiple feeds here. /** Register Our RSS Feeds **/ function my_rss_templates() { add_feed( 'feedname2', function(){ get_template_part('rss', 'feedname2''); }); // Rinse and Repeat... } ...


1

You could move the logic into a class that remembers the names and the template parts. Example, not tested: class Custom_Feeds { private $feeds = array (); /** * @param array $feeds */ public function __construct( Array $feeds ) { $this->feeds = $feeds; } /** * @wp-hook wp_loaded * @return void */ ...


1

This should work for the rel attribute: /** * Create a rel attribute from the image categories * * @see http://wordpress.stackexchange.com/a/158024/26350 */ add_filter( 'get_image_tag', function( $html, $id ) { $rel = array(); foreach( (array) get_the_category( $id ) as $cat ) { $rel[] = $cat->slug; ...


1

get_userdata() returns you the data of a specific user (by id), while get_currentuserinfo() returns data about the current logged in user. For example, you could use get_currentuserinfo() to welcome a user (e.g. "Welcome back John"), if he's signed in.


1

Here is the problem If you try to register or enqueue an already registered handle with different parameters, the new parameters will be ignored. Instead, use wp_deregister_script() and register the script again with the new parameters. You will have to deregister jquery first, the register it again, but becareful because the empty string isn't ...


1

The requires are just echoing the content, you need to put ob_start(); before the if ($query->have_posts()) :, and return ob_get_clean(); after the endif;.


1

pre_get_posts and WP_Query uses the exact same parameters, so if you need to know which parameters you can use with pre_get_posts, simply visit the WP_Query page in the codex. There is another trick which you can use to get all the parameters (query_vars) you can use. Just add this on the page that you need to get the query_vars from, refresh the page, and ...


1

This could be the matter of adjusting the priority of your filter callback, since the plugins files are executed before the functions.php theme file. That could explain why it works in your functions.php file, if the priority is the same. When you add the code snippet to a plugin, it might be executed before the other plugins that use the same filter. The ...



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