doubeiji2602 2016-07-05 12:08
浏览 93


I'm working on registration form and use a simple captcha php script to generate captcha image.

This is the html code used to display the captcha image on the page

<img id="img" src="captcha.php">

Everything worked fine on the static version of the page, but the image doesn't show on Wordpress generated page.

Is it possible to display my captcha image in Wordpress page without using any plugins ?

EDIT: I'm adding a bit more of my code

My page.php file

<?php get_header(); ?>
<?php while ( have_posts() ) : the_post(); ?>
  <div class="row">
    <div class="col-md-9 col-left-outer">
        <div class="col-md-12 col-left">
            <img id="img" src="'.home_url().'/captcha.php"> <-- Added this line to test if captcha will display from page.php file -->
            <?php the_content(); ?>
    <div class="col-md-3">
        <div class="col-md-12 col-right">
          <!-- Archive Side Navigation -->
            <?php get_sidebar(); ?>
 <!-- /.row -->
<?php endwhile; wp_reset_query(); ?>
<?php get_footer(); ?>

The code I input in the textbox in Wordpress dashboard

<div class="row">
   <div class="col-lg-4 col-md-4">
      <label for="InputName">Παρακαλούμε, εισάγετε CAPTCHA</label>        
      <img id="img" src="'.home_url().'/captcha.php">
      <input id="captcha1" class="form-control" name="captcha" type="text" required>
  • 写回答

1条回答 默认 最新

  • dongyuan8024 2016-07-05 12:43

    Since WP uses .htaccess to rewrite, you should not use a relative path as in
    src="captcha.php", but an absolute path like
    src="" or

    You will have to adapt the paths above to your configuration.

    WP knows where your site is located, so to be independent, use something like:

    echo '<img id="img" src="' . home_url() . '/captcha.php">';


    <img id="img" src="<? php echo home_url() ?>/captcha.php">

    <?php will only work if in a plugin or template. If your html code is only in a WP Widget text Content, the PHP will not be parsed for security reasons.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



    • ¥100 正常上网,内部网页无法打开
    • ¥15 组件库引入并使用在若依框架未展示
    • ¥149 关于#使用python 的Flash Echarts+ajax+mysql动态数据实现饼图#的问题,请各位专家解答!
    • ¥15 RichTextBox中追加文本时报错
    • ¥15 关于c语言的学习问题
    • ¥15 activity升级到flowable工作流act_ge_bytearray的草稿json数据复制到act_de_model 的model_editor_json的脚本
    • ¥15 cvi使用CreateThread创建线程时,出现存储空间不足无法处理此命令的错误
    • ¥15 求苹果推信imessage批量推信技术
    • ¥15 ubuntu 22.04 系统盘空间不足。隐藏的docker空间占用?(相关搜索:移动硬盘|管理系统)
    • ¥15 c++ word自动化,为什么可用接口是空的?