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


11

This is an alternative approach to @kaiser answer, that I found pretty fine (+1 from me) but requires additional work to be used with core WP functions and it's per-se low integrated with template hierarchy. The approach I want to share is based on a single class (it's a stripped-down version from something I'm working on) that takes care of render data for ...


9

Basic separated data structures To pass around data, you normally utilize a Model (that's the "M" in "MVC"). Let's look at a very simple interface for data. Interfaces are just used as "Recipes" for our building blocks: namespace WeCodeMore\Package\Models; interface ArgsInterface { public function getID(); public function getLabel(); } Above is ...


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


7

If you need this to be a PHP solution. You could do something like this using 'the_content' filter. This will add the class name "content-img-wrap" to any paragraph that wraps only an image tag when Wordpress prints your post content. So this will not wrap a paragraph with an image and a span. See update if that is what your looking for. add_filter( ...


6

You can use get_the_title() to return the current post title in the loop.


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

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' ); }


6

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


5

I am not sure why your query is returning more IDs than necessary. The $args for get_users look correct. By default get_users does not support orderby=rand, but you can overwrite that option. See below: function random_user_query( &$query ) { $query->query_orderby = "ORDER BY RAND()"; } // Usage: [random_users how_many = 3] add_shortcode( ...


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


6

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.


5

If you look at the source code of get_the_archive_title(), you will see that there is a filter supplied, called get_the_archive_title, through which you can filter the output from the function. You can use the following to change the output on a category page add_filter( 'get_the_archive_title', function ( $title ) { if( is_category() ) { ...


5

All you can do is bump the priority of your hook: add_action( 'wp_head', 'dns_prefetch', 0 /* Highest priority */ ); but does this put my code just after the start of tag? No, but it will output before any other function attached to wp_head i.e. other <link />'s, most stylesheets, plugin scripts etc. To put it right after <head> you'll ...


5

Via using the dynamic_sidebar() you can change/edit the widgets in the widgets area of the appearance settings. If you use the_widget() you hard code it straight to template so you need to modify the code to change what is displayed. Both have their uses. Too many sidebars tend to clutter the widgets area, but is very good for users that don't want to mess ...


4

Simple answer, don't pass variables anywhere as it stinks of using global variables which is evil. From your example it seems like you are trying to do an early optimization, yet another evil ;) Use the wordpress API to get data which is stored in the DB and don't try to outsmart and optimize its usage as the API do more then just retrieving values and it ...


4

You can make use of the conditional tag is_page_template() This Conditional Tag allows you to determine if you are in any page template. Optionally checks if a specific Page Template is being used in a Page. This is a boolean function, meaning it returns either TRUE or FALSE. You can try something like if( is_page_template( 'template-flat.php' ) ) { ...


4

I doubt it would justify the effort of writing custom SQL queries for only 2500 posts. Within the wp_set_object_terms( $object_id, ... ) function we have: $object_id = (int) $object_id; so it's correct that it only takes a single post id as input. So you would need to loop over your $post_ids array but it might be sufficient to use the ...


4

You can set the expire date as post meta value. In single.php you can easily show that date by querying the post meta. See update_post_meta() and get_post_meta() Now, the second part of your question is pretty tricky. I can think of 2 solutions. Cron You can use wordpress cron to run at a time interval to check which post has been expired and ...


4

The is_login_page() function is taken from here function is_login_page() { return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php')); } function my_redirect() { //if you have the page id of landing. I would tell you to use if( is_page('page id here') instead //Don't redirect if user is logged in or user is trying to sign ...


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

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


3

Of course there are better ways to do that. You could use some local installation with a copy of your online website with software such as WAMP, XAMP, etc to make your changes. "Cow Boy" coding is never a good solution. If you miss one ; boom! Fatal error! And in your case this is live. You could also use better process such as git workflows to have a ...


3

The last line tells WP to run this function on the pre_get_posts hook. That hook is the ideal place to modify the main query that will be run in order to build the page. In this case, exclude_featured_tag() checks whether WP is loading the home page, and whether it's about to call the main query for the page (as opposed to any other secondary queries being ...


3

First, like many things in WordPress, it's not like someone decided "let's make this neat and convenient". It was more like someone slapped it together for something, then it got used more in admin, then it got used a lot in admin, then it became kind of practice to use it for non-admin as well. Or something along these lines. Second, it's not as much what ...


3

The quick fix is to wrap your image tags in div tags. That will prevent WP from wrapping the images in P tags. Then, you could give the divs a class for further control of appearance/arrangement.


3

Please change the type type : "GET", to type : "POST",



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