How to set a different value in the generator meta tag?

Actually there is no hook there to change the texts on the fly. So the way is like below: Let’s first remove the default one, use the following code in functions.php: remove_action( ‘wp_head’, ‘wp_generator’ ); Now show our new one, add the following code in functions.php: function wpse_custom_generator_meta_tag() { echo ‘<meta name=”generator” content=”Mr. Kauwa Kala” … Read more

Is possible dequeue/remove style from wp_footer() hook and add on wp_head() hook?

If you look at the source code, you can see that wp_enqueue_style( ‘crayon’ ) is called in Crayon::enqueue_resources() which itself is called either from either Crayon::the_content() or Crayon::wp_head(). The code in Crayon::wp_head is: if (!CrayonGlobalSettings::val(CrayonSettings::EFFICIENT_ENQUEUE) || CrayonGlobalSettings::val(CrayonSettings::TAG_EDITOR_FRONT)) { CrayonLog::debug(‘head: force enqueue’); // Efficient enqueuing disabled, always load despite enqueuing or not in the_post self::enqueue_resources(); } … Read more

How to run an add_action hook for specific page

Put is_page() inside the callback function: function include_regForm_validation() { wp_register_script( ‘jQuery_form_validation’, ‘https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.js’,array(‘jquery’), ‘1.0’, true ); if ( is_page( ‘login’ ) ) { wp_enqueue_script( ‘jQuery_form_validation’); } } add_action( ‘wp_enqueue_scripts’, ‘include_regForm_validation’ ); WordPress has not determined what page/archive has been requested yet when hooks are added with add_action(), so you need to make the determination only when … Read more

Use debugging for add action events

If you want to use debugging from an action where you won’t see the output, you can send things to error_log. First, you need to enable debug logging. In your /wp-config.php add the lines: define( ‘WP_DEBUG’, true ); define( ‘WP_DEBUG_LOG’, true ); This will create a file called /wp-content/debug.log Next, in your code, add some … Read more

How to get multiple Action Hooks in an Array

If you want to hook into multiple actions, you have to call add_action multiple times. However, this is not so hard. Let’s take your plugin class as an example: class WPSE6526_getStatic // Always prefix your plugin with something unique, like your name. Here I used the question number { var $_renderTasksOn = array( ‘wp_insert_post’, ‘wp_insert_comment’, … Read more

How can I automatically set a post slug based on the post title during post publish?

As long as haven’t touched the slug WordPress will generate a new one after you entered a title. Update To change other peoples slugs use a filter (not tested!): add_filter( ‘wp_insert_post_data’, ‘prevent_numeric_slugs’, 10, 1 ); function prevent_numeric_slugs( $post_data ) { if ( ! isset ( $post_data[‘post_title’] ) or ! is_numeric( $post_data[‘post_name’] ) ) { // … Read more

Get post id in wordpress action?

I haven’t tested so I’m providing you with two possibilities, Inside a loop, use the following: $post_id = get_the_ID(); Outside a loop, use the following: global $wp_query; $post_id = $wp_query->post->ID; Or: global $post; $post_id = $post->ID Or you can pass the post ID in a function, much like function my_function($post_id){ // code }

where is the documentation for add_action() parameters?

those parameters aren’t unique to the_posts, they’re parameters for the add_action() function add_action( $tag, $function_to_add, $priority, $accepted_args ); the 10 is just the default priority and 1 is the default number of accepted arguments. since they’re both default, you don’t really need either. http://codex.wordpress.org/Function_Reference/add_action