WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any way to replace standard WordPress comments form action, which usually looks like this:

<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">

to something custom WITHOUT altering comments.php (i.e. for a plugin, so you don't have to make end-users edit their themes):

<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" some_java_script some_tag="some_value" method="post" id="commentform">

share|improve this question
    
I don't need to replace action URL, I need to add some stuff in <form> tag, just like it's shown in the original post (see last 2 lines). – user7342 Jul 26 '11 at 9:27

simple with jQuery:

//first make sure you have jQuery on that page
add_action('wp_enqueue_scripts','make_sure_i_have_jquery');
function make_sure_i_have_jquery(){
    if (!is_admin())
        wp_enqueue_script( 'jquery' );
}
//then just change the url to you own
    add_action('wp_footer','change_comment_form');
    function make_sure_i_have_jquery(){
        if (!is_admin() && (is_page() || is_single()))
            echo '<script> $("#commentform").attr("action", "http://yourUrl.com"); </script>';
    }

just paste this in your theme's functions.php or the plugin your are develop and change http://yourUrl.com to the url you want

share|improve this answer

paste this in your theme's functions.php:

add_action( 'comment_form_before', 'my_comment_form_before' );
function my_comment_form_before() {
    ob_start();
}
add_action( 'comment_form_after', 'my_comment_form_after' );
function my_comment_form_after() {
    $html = ob_get_clean();
    $html = preg_replace(
        '/wp-comments-post.php"/',
        'wp-comments-post.php" some_java_script some_tag="some_value"',
        $html
    );
    echo $html;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.