WordPress

WordPress – how to install WP-CLI on Ubuntu

machine à écrire sur un bureau en bois

Start by downloading wp-cli curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar Then give it the right to be executed chmod +x wp-cli.phar Then move it to /usr/local/bin to be able to use the wp command sudo mv wp-cli.phar /usr/local/bin/wp To use the command, simply go into the folder containing the WordPress installation $ wp NAME wp DESCRIPTION Manage WordPress … Read more

Read the article →
WordPress

WordPress – How to add or remove a TinyMCE button

boutons de couture de toutes les couleurs

By default on WordPress we have TinyMCE and although this plugin is very powerful, there are far too many buttons. Fortunately with a few lines of code, it is possible to configure it. In your theme’s functions.php file or in your plugin, use the hook as follows: function configure_mce( $init ) { // nos options … Read more

Read the article →
WordPress

WordPress – how to retrieve the ID from a given meta

étiquette de prix électronique dans un rayon

With WordPress, it is common to use the get_post_meta($post, $meta_key) method in order to retrieve the value of a given meta. However for the ID, there is no ready-made method. The best solution I’ve found so far: $mid = $wpdb->get_var( $wpdb->prepare(“SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s”, $post, $meta_key) );

Read the article →
WordPress

WordPress – How to run a LIKE query with WP_Query

empreinte digitale sur le bout d'un doigt

To make queries on WordPress, I’m used to using WP_Query($args). In this example, we want to add a LIKE = “%title%” in our query. Here is a simple request that adds all our posts in the array a_response_array: $args = array( ‘post_status’ => ‘publish’, ); // The Query $query = new WP_Query( $args ); // … Read more

Read the article →
WordPress

WordPress – Character counter for the caption field of an image

appareil photo ancien devant des fleurs

For every WordPress image, we can add a caption or a title. It may be useful to add a counter. To do this, you must use both hooks admin_head-post.php and admin_head-post-new.php function cf_caption_count_js() { echo ‘<script type=”text/javascript”> jQuery(document).ready(function() { jQuery(“#attachment_caption”).wrap(“<div></div>”); jQuery(“#attachment_caption”).parent().css(“display”, “table”); jQuery(“#attachment_caption”).parent().css(“width”, “100%”); jQuery(“#attachment_caption”).after(“<span id=\’cf_caption_count\’ style=\’display:table-cell; width: 30px; margin-left: 5px; text-align: right;\’></span>”); jQuery(“#cf_caption_count”).html(jQuery(“#attachment_caption”).val().length); jQuery(“#attachment_caption”).keyup(function() … Read more

Read the article →