Tag Info

Hot answers tagged

7

This has always been a bugbear for me - the lack of on-demand image sizing, and the subsequent number of files you can end up with if you have lots of sizes! I can see the logic behind your efforts - the trouble is, add_image_size only truly comes into play at point-of-upload. As such, is_page_template(..) will always be false. A quick google dug up Aqua ...


4

Disclaimer: - This isn't actually an answer. - It is intended to help you with your additional research on the topic. - Furthermore it is reflecting a - at least felt - lately more frequent occurrence of similar questions regarding similar problems. Additional information regarding this topic on Wordpress Development: Removing Image Sizes for ...


4

I am doing something like this in one of my plugins: function my_body_class( $c ) { global $post; if( isset($post->post_content) && has_shortcode( $post->post_content, 'your-shortcode' ) ) { $c[] = 'your-class'; } return $c; } add_filter( 'body_class', 'my_body_class' ); I'm not sure it was really necessary, but I ...


4

Is there more efficient ways to validate the quotes using the WordPress api? I think you should set a nonce for the form You also should check if current user has capability to save quote To get properly sanitize values form $_POST look at filter_input and/or filter_input_array I don't see performance issues on validation, but a possible ...


3

add_theme_support( $feature, $arguments ); as you can see have two parameters, $feature and $arguments. $feature is the feaure you need to add theme support for. This parameter doesn't accept an array, only a string. So you would have to add a add_theme_support for every feauture that you would like to include in your theme. In your question, it is ...


3

When you pour some water into a glass, first you put the glass on the table, then you turn the bottle. If you first turn the bottle, and then put glass on the table, your floor gets wet and your glass stay empty. Actually wp_enqueue_scripts is just a way to save a variable (water) inside a global object (glass), so before to call the function (turn the ...


2

It's certainly possible but you're probably looking at doing an ajax request on the image click which in turn executes the short code and returns the output. This involves three distinct steps, binding the ajax request to an action, executing the ajax request and handling the response, and actually writing the script that will process the request. This ...


2

As @gate_engineer already stated, your problem is a plain PHP problem where you are trying to access an Object as Array. To not only state that, but help you a bit further, the correct check for a proper response object is checking against the return value of wp_remote_retrieve_response_code() and wp_remote_retrieve_response_message(): $response = ...


2

You should first load your scripts with a hook on wp_enqueue_scripts like this for example : add_action( 'wp_enqueue_scripts', 'load_my_scripts' ); function load_my_scripts() { wp_enqueue_script( 'jquery' ); } What I like to do is, register my script with a hook on init and then enqueue them with a hook on wp_enqueue_scripts: // Register Scripts ...


2

Scripts and stylesheets should always be loaded in the head or in the footer via the wp_enqueue_scripts action hook. wp_enqueue_scripts is the proper hook to use when enqueuing items that are meant to appear on the front end The init hook executes before wp_head which is to early for script to load in the header. The wp_enqueue_scripts action hook is ...


2

If you want to create thumbs on the fly you can use Aqua image resizer, But there is a drawback of this mini script. The created thumbs will not delete upon deleting image from library. But its not a big deal. If required you can do so via SHH commands


2

If you check the source ... 1361 /** 1362 * Allows a theme to register its support of a certain feature 1363 * 1364 * Must be called in the theme's functions.php file to work. 1365 * If attached to a hook, it must be after_setup_theme. 1366 * The init hook may be too late for some features. 1367 * 1368 * @since 2.9.0 1369 * @param string ...


2

If you hook your localize script function to wp_enqueue_scripts, then you will have access to the global $post variable. As long as you pick a hook at or after 'wp' you should have access to the global $post. <?php add_action('wp_enqueue_scripts', 'YOUR_NAME_scripts'); function YOUR_NAME_scripts() { wp_enqueue_script('YOUR_NAME-js'); ...


2

Yep, wp_trim_words(): <?php $trimmed = wp_trim_words( $text, $num_words = 55, $more = null ); ?> Or in your case: <?php echo apply_filters( 'the_content', wp_trim_words( strip_tags( $post->post_content ), 55 ) ); ?>


1

Per the Codex: relation (string) - The logical relationship between each inner taxonomy array when there is more than one. Possible values are 'AND', 'OR'. Do not use with a single inner taxonomy array. So you are on the right track, but your tax_query is wrong. relation is part of the outer tax_query array and not part of the top level query ...


1

There are a lot of ays to do the trick, one possible is use a function that use a static variable. However, before you can be able to get the arguments set in shortcode, the shortcode must be processed... function foobar_func( $atts = array(), $out = FALSE ){ static $args = array( 'foo' => 'default foo', 'bar' => 'default bar' ); ...


1

The CSS for my parent theme (core) was incorrectly formatted. The code at the top read: Theme Name: Core Theme URI: http://www.domain.co.uk Description: The core theme. Author: Squideyes Author URI: http://www.domain.co.uk Template: Core Version: 1.0.0 Tags: clean, simple, easy The Template: tag should only appear in the child theme css. This is what ...


1

You can use the awesome WP_Admin_Bar & hook in with admin_bar_menu: /** * Add a "Log out" link directly to the admin bar. * * @link http://wordpress.stackexchange.com/q/141446/1685 * * @param WP_Admin_Bar $wp_admin_bar */ function wpse_141446_admin_bar_logout( $wp_admin_bar ) { if ( is_user_logged_in() ) { ...


1

It is not a direct answer for your problem. But I will help you to make image according to your need. When you use add_image_size it does not resize the existing images. it only works for the new images that will be uploaded after adding your add_image_size function. So your code will not generate new images for is_page_template function. But you can use ...


1

I know this is kind of a backwards way of doing it, but I suppose if you disable the possibility to upgrade the plugin, then you don't need to worry about the plugin being overwritten. Change the plugin version number (in the plugins main file comment header) to something ridiculously high so it won't recommend an upgrade to the user. I've had to do ...


1

References: wp_remote_post() The WP_Error Class Stopping the Fatal Error: The error that you're receiving above is due to the fact that wp_remote_post() returns a WP_Error object if a request to the remote web server failed. When the script executes the next expression on line 63: if ( $response['response']['code']!='200' ) ...PHP gets confused as to ...


1

The problem is that you can't distinguish form an anonymous function and another, so yes, it is possible to remove a closure (i.e. anonymous function) but if more than one closure act on same filter at same priority you have to make a choice, remove them all, ore remove only one (without knowing exactly which). I'll show how to remove them all using a ...


1

Instead of redirecting to a new page, you can use the one you're already on with basic logic similar to this: if ( !empty( $_POST['ticket_action'] && ( $_POST['ticket_action'] == 'noshow' ) ) { $ticket_post_id = $_POST['ticket_post_id']; ... you probably want to check if the user is logged in or check for a valid nonce here ... // do ...


1

Here is the function that I use to display CPT in the "At a glance" widget add_action( 'dashboard_glance_items', 'cpad_at_glance_content_table_end' ); function cpad_at_glance_content_table_end() { $args = array( 'public' => true, '_builtin' => false ); $output = 'object'; $operator = 'and'; $post_types = ...


1

Okay, so I used this code to only display "wrestler" post type & it worked. I mixed mine & Pieter Goosen's code to get this out: add_filter( 'dashboard_glance_items', 'custom_glance_items', 10, 1 ); function custom_glance_items( $items = array() ) { $post_types = array( 'wrestler' ); foreach( $post_types as $type ) { if( ! ...


1

The parent theme's functions.php will load automatically. You don't need to "read" it, and you don't want to "hack" it either manually, which will be overwritten, or programatically, which is very resource intensive. Your theme is enqueueing the script on the wp_head action. You just need to remove that callback and add a slightly modified one. The trick ...


1

The default image size for inserting images is stored in the options table in image_default_size. You can change the default image size by updating the option: update_option( 'image_default_size', 'large' ); Role-dependent default image size To change the default image size for contributors only, you could hook into pre_option_[option] filter (which is ...


1

The following gets called by WordPress while getting the reply link. apply_filters( 'comment_reply_link', $before . $link . $after, $args, $comment, $post ); Use a custom filter to provide your own link. I don't believe there is a direct way of altering just the URL, you have to inject the url into an html string yourself. add_filter( ...


1

If you really want to execute code stored in a database, a quick google search reveals that you can use the eval() function to do just that. However, many people do say that Eval is Evil... Instead of storing the entire PHP code of an option in the database, try storing a simple boolean flag for your option and then test whether to get your template's ...


1

1) create one template page on your page-templates dir in landingpage.php with this code page-templates/landingpage.php <?php /** * Template Name: Landing page */ ?> <div id="main-content" class="main-content"> <div id="primary" class="content-area"> <div id="content" class="site-content" role="main"> ...



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