0

I am using <?php comments_template(); ?> to show my comment form and I'm trying to remove the url field so I added this to my functions

add_filter('comment_form_default_fields', 'clear_url_box');
function clear_url_box($fields){
    if(isset($fields['url']))
    unset($fields['url']);
    return $fields;
}

this is my single.php

<?php get_header(); ?>
<div id="content">
<div id="singleimg">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

            <div id="post-<?php the_ID(); ?>">
                    <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
                    <?php the_content('Read more on "'.the_title('', '', false).'" &raquo;'); ?>

                    <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
                    <div id="tags"><?php the_tags( '<p>Tags: ', ', ', '</p>'); ?></div>


</div>

    <?php endwhile; else: ?>

                <p>Sorry, no posts matched your criteria.</p>

    <?php endif; ?>
    </div>
<?php comments_template(); ?>

</div>
<?php get_footer(); ?>

but it's not working. Anyone know how to fix this? my site is http://toarumajutsunoindex.me/test/

  • It worked for me. – M-R Jul 26 '13 at 11:03
  • it doesn't work for me :( I added my site for you to see live – Ruriko Jul 26 '13 at 11:15
  • Make sure you are putting it in right theme. Confirm it by placing an exit; call. Plus, adds a third priority parameter and set it to 99 (just in case). – M-R Jul 26 '13 at 11:22
  • Can you show us your comments.php template? – Krzysiek Dróżdż Jul 26 '13 at 13:17
1

Your theme should have a comments.php file. Can you just remove the field there? For instance, my comments.php files has the following code:

    <p class="field"><label for="url"><?php _e('Website', 'theme1721'); ?> </label><input type="text" name="url" id="url" value="<?php echo esc_attr($comment_author_url); ?>" size="22" tabindex="3" /></p>

I would just remove it if I didn't want visitors to have the option to leave a url.

  • 3
    I'm pretty sure your answer isn't always correct. WordPress themes should use comment_form function, so there is a chance, that you won't find this field. – Krzysiek Dróżdż Jul 26 '13 at 13:17
-1

The Easy Way

The least destructive way is also the easiest, using CSS:

#commentform > p.comment-form-url {display:none;}

The Hard Way

Open \wp-includes\comment-template.php and remove or comment out the following lines:

    'url'    => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .
                '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>',
  • Do not edit core files; they will be overwritten after the next update. Use the existing filters instead. – fuxia Mar 1 '17 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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