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

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.


2

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; ...


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" ) ); } ...


2

Redefining a WordPress core function that might be used all over the place by the core, the theme or plugins isn't a very good idea in my opinion. Because it might be used in those occasions expecting the default value to be what default is, which might lead to breaking things. So it is actually not just not a very good idea, it is a terrible one - in my ...


2

I haven't tested this but theoretically you could do something like this (Using the Codex as an Example): function load_custom_wp_admin_style() { $pageArr = array(1, 2, 3); if(isset($_GET['post']) && in_array($_GET['post'], $pageArr)){ wp_register_style( 'custom_wp_admin_css', get_template_directory_uri() . '/admin-style.css', false, ...


1

The method rmdir() - source - : /** * Delete a directory. * * @since 2.5.0 * * @param string $path Path to directory. * @param bool $recursive Optional. Whether to recursively remove files/directories. * Default false. * @return bool Whether directory is deleted successfully or not. */ public function rmdir( $path, $recursive = false ) { return ...


1

Assuming your products are custom posts you can do it like this: add_action('wp_insert_post', 'do_stuff'); // when product is created add_action('save_post', 'do_stuff' ); // on product update function do_stuff( $post_id ) { // Making sure this runs only for products $slug = 'product_post'; if ( $slug != $_POST['post_type'] ) { ...


1

The problem is that when you pass the $key argument on get_user_meta() function, you don't pass a valid argument. The $key must be a string according to the documentation page. It represents the value of meta_key in the wp_usermeta table. If with wpcf-client-lvl is actually a variable that contains the name of the field ( lets say $wpcf-client-lvl = ...


1

If your update_option call runs after you assign $posts1 and $posts2, then of course they'll hold the "old" value, even if you sleep for eternity ;) Either run the update earlier, or (re)assign the variables afterwards. $posts1 = get_option( 'post1' ); echo get_option( 'post1' ); // [my_id] echo $posts1; // [my_id] update_option( 'post1', 'foobar' ); ...


1

Auto-generate shortcodes from an array: You can try the following Shortcode Automat: /** * Setup the Shortcode Automat * */ function shortcode_automat_setup() { $settings = array( "get_address" => "mg_admin_address", "get_phone" => "mg_admin_phone", "get_fax" => "mg_admin_fax", "get_email" ...


1

Here is a great example. How to display featured post thumbnails in WordPress feeds paste this code snippet in your theme functions.php file // display featured post thumbnails in WordPress feeds function wcs_post_thumbnails_in_feeds( $content ) { global $post; if( has_post_thumbnail( $post->ID ) ) { $content = '<p>' . ...


1

When it comes to the template hierarchy, WordPress will indeed look in the child theme directory before loading from the main theme. For all other non-specific WordPress files (like functions and 3rd party includes), it's entirely up to the main theme to decide how to load them. Unless the theme is using locate_template to load these includes, or is ...


1

The $hook_suffix global (copy of which you are getting passed to the hook) doesn't go into such detail. However there is plenty more of context to check. In modern WP versions bulk of it is via get_current_screen() which returns WP_Screen object with plenty of stuff (in this case you would want to check id and post_type properties likely). As for post's ...


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

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

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

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

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 ...


1

I'd probably try only enqueueing those scripts on specific pages, rather than enqueuing and then dequeuing them: function wpse158453_enqueue_scripts() { if(!is_page('my-page')) { wp_enqueue_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js' ); wp_enqueue_script( 'jquery-ui', ...



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