Tag Info

Hot answers tagged

13

The default response from admin-ajax.php is, die( '0' ); ...by adding your own exit() or die() after returning your desired content prevents the default response from admin-ajax.php being returned as well. It also generally means that your ajax call has succeeded. Ultimately, to answer your question, it's meant to work this way. What you are doing by ...


10

Add this snippet to your functions.php function redirect_the_single_post() { if (is_search() && is_main_query()) { global $wp_query; if ($wp_query->post_count == 1 && $wp_query->max_num_pages == 1) { wp_redirect( get_permalink( $wp_query->posts['0']->ID ) ); exit; } } } ...


10

the_permalink echos out the permalink of the current post to the frontend. get_permalink however returns it as a variable, but does not echo it out. You can also pass a post ID to it if you want the permalink of another post. the_permalink is equivalent to: echo get_permalink(); Which is very close to what it actually does. This is the implementation of ...


9

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


8

Use the second parameter of edit_post_link(), the before parameter: <?php edit_post_link( 'Edit', 'string of text: ' ); ?>


6

The Reply links I assume your Reply links look like this: <a class="comment-reply-link" href="/2013/12/29/hello-world/?replytocom=32#respond" onclick="return addComment.moveForm('comment-32', '32', 'respond', '1')">Reply</a> and the Cancel Reply link: <a rel="nofollow" id="cancel-comment-reply-link" ...


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'];


5

If this is how it looks: <img class="alignleft size-medium wp-image-8530" alt="..." src="#" width="413" height="275" /> <img class="alignleft size-medium wp-image-8529" alt="..." src="#" width="413" height="275" /> Then you have to put them together like this: <img class="alignleft size-medium wp-image-8530" alt="..." src="#" width="413" ...


5

This answer contains a fairly simple CSS solution. Essentially, you'd add the following to your stylesheet: .cat-item cat-item-7 { list-style-image: url('my-epic-news-icon'); } cat-item cat-item-11 { list-style-image: url('my-epic-jquery-icon'); } etc Yes, it's not a very dynamic solution, but your categories aren't likely to change I ...


5

The second $item argument, which is being made available to your filter function, contains a menu item object. If dumped it looks something like this: [1] => WP_Post Object ( [ID] => 2220 [post_author] => 1 [post_date] => 2012-12-26 19:29:44 [post_date_gmt] => 2012-12-26 17:29:44 [post_content] ...


5

t f's answer got me thinking. Actually, I can use the core function and adapt it as I like but just put everything in a new function. So here goes: function my_wp_is_mobile() { static $is_mobile; if ( isset($is_mobile) ) return $is_mobile; if ( empty($_SERVER['HTTP_USER_AGENT']) ) { $is_mobile = false; } elseif ( ...


5

There is no real difference between the two methods. When using method A, only the hooking is bound to the condition (i.e., the function is defined no matter what), while in method B the definition of the function as well as the hooking is. Another thing is the following method (which you did not include): function my_hooked_function() { if (! ...


5

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


5

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

Redeclaring a function in a child theme only works when the parent themes' function is wrapped in a if( !function_exists( 'function_name' )): condition. Then you can simply just copy the complete function to the child theme and do whatever modifications you need to do. If the parent themes' functions aren't wrapped in that if conditional statement, and ...


4

Anywhere in your script, you can define a global variable as follow: Using the superglobal $GLOBALS array. This array is predefined by PHP, and is available in all scopes. It's an associate array, containing all global variables as a key-value pair. ie: the key will be the variable name, and value will be the value of the variable. ...


4

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


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


4

What you are looking for is a "MU-Plugin"-- "Must-Use Plugin".. Originally these were called "Multi-User Plugins" and were intended for exactly your purpose-- to provide a way for site admins to enable functionality on all sites of an installation. Create a directory at /wp-content/mu-plugins/ and put your PHP file(s) in it. WordPress will load the files ...


4

The internal implementation details of that feature are of questionable sanity. If you take a look at said featured-content.php template you would see that it get posts from twentyfourteen_get_featured_posts() however the only thing that function has is twentyfourteen_get_featured_posts filter from quick look at which in peculiar fashion nothing is ...


4

Yes, you can replace existing icons by overwriting them via CSS. Make sure to check if the existing icon is set via img or background-image and add some CSS to overwrite it with one of the available icons. You can find all available icons and the appropriate selector at the Dashicons Website. To replace the icon of the Yoast SEO Plugin you can add this ...


4

Your problem is here: $welcomePage = get_post( 5 ); echo $welcomePage -> post_content; Shortcodes are processed on display by via a filter on the_content which is called by the function the_content(). You've bypassed that functionality and are echoing the raw post data. You need to output your code using a proper Loop or explicitly process the ...


4

And there is another filter that will give you access to the $header variable which can allow you to BCC your emails so that you get a carbon copy of every email that goes to your clients on Woocommerce. This is just as easy as the code above except your clients will not see your email address. Just like the solution above you would add the following code: ...


4

The problem with the code in your question is it always intercepts. You completely lose the ability to not publish, no drafts possible. Why this leads to untrashable post is something I didn't inspect further. Anyway this isn't what one wants. I'm glad the javascript solution is working for you, but personally I have two problems with it, first, you can ...


4

Assumptions: You don't explain how you want to install the Font Awesome package, so I just assume for the moment that you use the plugin Font Awesome Icons. You wrote: Before anyone says use a background image, I do not want to do that. I would like it to be physical. so I assume you want to use the <i> tag directly, for example: <i ...


4

Basically every filter has to be registered in the original function code (since a filter is just a way you can overwrite what is happening in the default function). So before you can attach your custom function to a filter using add_filter() the filter has to be registered before with apply_filters() (there are other functions which do the same - but this ...


4

If it is a custom theme for your site then there would no great speed or security improvements by moving functions. On the other hand if you want to distribute the theme then I recommend having only the minimum php in the page templates files and having the rest of the functions organized in different files. I like the basic theme set up files of the theme ...


4

Assuming that you want to use the fa-chevron-right icon, you simply need to target the list item via CSS. Use the :after pseudo-class: .list-item:after { font-family: FontAwesome; // or whatever the font awesome family is registered as content: '\f054'; } Edit So, to give an idea of how you might pass dynamic CSS (which can be easily adapted to a ...



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