New answers tagged

0

I don't know any other way There is a much, much better way to do this - custom fields. As per these instructions in the custom fields docs, let's say you use the field name iframe_url: <iframe src="<?php echo esc_url( get_post_meta( $post->ID, 'iframe_url', true ) ?>" width="960" height="540" frameborder="0" allowfullscreen="...


5

It is not a bug. As @LuisSanz pointed out, post_type_link isn't used for the built-in post post type. It is used for custom post types only. Skim through get_permalink() function, you will find out that WordPress doesn't use post_type_link filter but uses post_link filter. It means that you're using wrong filter. Then, change post_type_link to post_link ...


0

I think it is always better to use the API, the functions of WP in this context. The function wp_load_alloptions() is under maintain and a custom select must always tested and maintain. Also the function use the Cache, if the installation support this. A good point for performance. The function supports also the Multisite installation, maybe this also a ...


1

Yep it's possible depending on what you want to cache. I've done a similar thing to cache the main loop on our homepage. Essentially you can use the posts_request and posts_results to hijack the query and hit the cache instead then also use found_posts to correct the pagination. Really rough example pulled from our code (untested) but you should help you ...


0

You can pass a priority parameter to add_action. I don't actually know what priority Akismet has (default is 10), but you could start by trying this: add_action( 'wp_default_scripts', 'pwcc_jquery_to_footer', 9);


4

Looking at the sources (core files, wp-includes/option.php) you can always find your target hook tags: add_action("added_option", "wpse230212_callback_add", 10, 2); add_action("updated_option", "wpse230212_callback_update", 10, 3); function wpse230212_callback_add( $option_name, $option_value ) { } function wpse230212_callback_update( $option_name, $...


0

As long as you don't delete your theme by ftp, but use the regular way of switching to another theme in the admin, there is a hook to use, switch_theme. It works like this: add_action('switch_theme', 'mytheme_setup_options'); function mytheme_setup_options () { delete_option('mytheme_option1'); delete_option('mytheme_option2'); } There's a sister ...


4

Your analogy here is partially correct, but incomplete: I understand that when do_action is called wp looks for all registered listeners and invokes them according set priority. You need to consider what happens when you call add_action. WordPress never searches for the add_action statements, it has those in a list. When you call add_action, it ...


0

All your actions belong in your functions.php, assuming that you are building a theme. It is here that you add actions to certain events in your templates. Now, once it has read functions.php WP has a list of actions it is supposed to undertake at certain points in your theme templates. There are several predefined action hooks, such as wp_head() and ...


3

do_action( 'deactivate_' . $plugin, $network_deactivating ); Fires as a specific plugin is being deactivated. do_action( 'deactivated_plugin', $plugin, $network_deactivating ); Fires after a plugin is deactivated. The above hooks don't fire when silent mode is activated (eg: during an update). Refer: deactivated_plugin


0

This is template_redirect Here : https://www.rarst.net/images/wordpress_core_load.png add_action('template_redirect', 'yourFunction');


0

Finally I found the solution in codex.... Interpreting the Error Message: If the error message states: Warning: Cannot modify header information - headers already sent by (output started at /path/blog/wp-config.php:34) in /path/blog/wp-login.php on line 42, then the problem is at line #34 of wp-config.php, not line #42 of wp-login.php. In this ...


2

It will be made possible in 4.6 (assuming no changes till release) with the new posts_pre_query filter https://core.trac.wordpress.org/ticket/36687


9

At the moment, it is not possible. When 'pre_get_posts' runs, is too late to stop WP_Query to perform a query. WordPress itself, when you try to query a taxonomy that does not exists, adds AND (0 = 1) to the WHERE clause of the SQL query, to ensure it returns no results very quickly... There's a trac ticket with a patch that will probably lands in core ...


2

This is PHP question more than a WordPress question. As @Mark commented: returning from the action do not return by magic from the calling function That is true. Placing return in function mean exit the function and placing return in a PHP file mean exit the file. Do not get confused with PHP construct exit() :P (You might find a better answer on SO ...


1

If you hook into the hooks provided in update_post_meta() function and still use this function in your callback, that would result in a loop which would probably end with the timeout.. As the per the comments: add_action("wp_insert_post", function( $post_ID ) { if ( ! $post_data = get_post( $post_ID ) ) return; // try to make this run only once ...


0

Because I couldn't find an answer on this, I handled it myself by setting my own cookie in the function and checking that. Here is the revised function: function custom_login_init () { $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'login'; if ( isset( $_POST['wp-submit'] ) ) { $action = 'post-data'; } else if ( isset( $_GET['reauth'] ) ) ...


2

The dynamic filter "term_{$field}" is probably what you're looking for, where the field is "name." One approach is to have an array of names and their pseudonyms, then do a check-and-return on them so they'll display the replacement. add_filter( 'term_name', function( $value ) { $terms = [ 'old' => 'new', ]; // basic example check, ...


0

So I found the solution to my problem. It is because WordPress inserts the dropdown both at the top of the list of users and on the bottom. So when i submit the form, it is the dropdown at the bottom of the page that is being used in the GET and overwriting the one at the top. To solve this issue I just removed the bottom dropdown with a line of javascript ...


0

add the following code to active theme. Here I am replacing with [shell] before saving. add_filter( 'content_save_pre' , 'my_sanitize_content' , 10, 1); function my_sanitize_content( $value ) { return str_replace("<shell>", "[shell]", $value ); }



Top 50 recent answers are included