Tag Info

Hot answers tagged

13

You are acting on awfully big assumption that something like that would improve performance. Spoiler — no, it won't. The load process in very loose terms consists of: Optionally running code responsible for looking up definitions (autoload or custom). Parsing the file or retrieving results from opcode cache. Loading results to be used. The "autoload is ...


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: ' ); ?>


8

functional interpreted code will always be faster then OOP one. Compare function hello_mark() { echo 'hello mark'; } hello_mark(); with class mark { function say_hi() { echo 'hello mark'; } } $m = new mark(); $m->say_hi(); I think it is obvious what is faster to interpret and execute. People don't do OOP because it is faster, they do ...


7

Best of luck to you, but this won't improve performance in any real way. WordPress is indeed becoming more and more object oriented, over time and with incremental changes. Every update in the last 4 years has refactored some major piece of code into a more class oriented design. Nevertheless, OO and autoload and other things like this are not inherently ...


7

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


6

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


6

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


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


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

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

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


5

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


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

PHP has a function, get_included_files() that returns all the file have been includedduring a request. However, if you use that fucntion you obtain all the files required: WordPress core files, plugin files... You need a way to: filter out files that do not belong to theme and child theme (if any) include only files loaded after main template has been ...


5

Try this: if ( has_excerpt( $some_post_id ) ) { // Do something here? } else { // Or here? } References: has_excerpt


4

As @cybmeta already pointed out, you are too early with your removal. So you have to defer the actual removal, for instance like so: add_action( 'after_setup_theme', 'wpdev_170663_remove_parent_theme_stuff', 0 ); function wpdev_170663_remove_parent_theme_stuff() { remove_action( 'after_setup_theme', 'et_pb_setup_theme' ); }


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.


4

If I understand the problem setup correctly, you could try to do the break and widget class counting within the wp_nav_menu_objects filter. Here's an updated example, it's rather expanded because of the extra debug part: add_filter( 'wp_nav_menu_objects', function( $items, $args ) { // Only apply this for the 'primary' menu: if( ...


4

Here's a much better solution: Don't edit the theme's functions.php file. Don't put your custom code into that file either. If you have snippets of code for a site, put them into a custom plugin. Put each one into its own plugin, in fact. Separate them by functionality. I even made a handy dandy plugin to make this easier, called Pluginception. The nice ...


4

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


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

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

You need to use one add_theme_support() call for each feature. Per the Codex, the proper function call is: add_theme_support( $feature, $arguments );


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

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



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