最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

posts - Contact Form 7 Shortcode not recognized inside another shortcode

programmeradmin2浏览0评论

I've created a code snippet with its shortcode to hide part of the post content for non-logged users: [private] ... [/private]

works great but when I try to put another shortcode (contact form 7) inside its not recognized. What could be the problem?

This is my code snippet:


function bp_contenido_privado( $atts, $content = null ) {
   if ( is_user_logged_in() )
   return $content;
   return '<p style="font-weight:bold;padding-top:10px;">Este contenido esta reservado para los usuarios registrados. Registrate <a href="'.wp_registration_url().'">aquí</a> o <a href="'.wp_login_url(get_permalink()).'">inicia la sesión</a> para poder verlo..</p>';
}

and this is the post content:

[privado]
<h4>Por favor llene los datos solicitados. Los formatos aceptados para subir archivos son pdf y jpg con un tamaño máximo de 2mb.</h4>
[contact-form-7 id="3584" title="Formulario de Inscripción"]
[/privado]

I've created a code snippet with its shortcode to hide part of the post content for non-logged users: [private] ... [/private]

works great but when I try to put another shortcode (contact form 7) inside its not recognized. What could be the problem?

This is my code snippet:


function bp_contenido_privado( $atts, $content = null ) {
   if ( is_user_logged_in() )
   return $content;
   return '<p style="font-weight:bold;padding-top:10px;">Este contenido esta reservado para los usuarios registrados. Registrate <a href="'.wp_registration_url().'">aquí</a> o <a href="'.wp_login_url(get_permalink()).'">inicia la sesión</a> para poder verlo..</p>';
}

and this is the post content:

[privado]
<h4>Por favor llene los datos solicitados. Los formatos aceptados para subir archivos son pdf y jpg con un tamaño máximo de 2mb.</h4>
[contact-form-7 id="3584" title="Formulario de Inscripción"]
[/privado]
Share Improve this question edited Mar 23, 2020 at 15:26 ominem asked Mar 23, 2020 at 15:17 ominemominem 231 silver badge5 bronze badges 5
  • Can you please post your shortcode function? Also, post how you are trying to pass the shortcode. – disinfor Commented Mar 23, 2020 at 15:19
  • already updated the question – ominem Commented Mar 23, 2020 at 15:33
  • I'm assuming you are seeing the shortcode code and not what you are expecting. What you can do to test is wrap $content in return do_shortcode( $content ); As a side note, I would strongly recommend wrapping your if statement in {}. Much easier to read. – disinfor Commented Mar 23, 2020 at 15:51
  • 1 It worked perfectly. Thank you. – ominem Commented Mar 24, 2020 at 8:41
  • I'll post as an answer for others. – disinfor Commented Mar 24, 2020 at 11:49
Add a comment  | 

1 Answer 1

Reset to default 0

You can wrap the entire return output in a do_shortcode(). That will render the shortcode as well as output the regular content.

function bp_contenido_privado( $atts, $content = null ) {
   if ( is_user_logged_in() ) {
      return do_shortcode( $content );
   }
   return '<p style="font-weight:bold;padding-top:10px;">Este contenido esta reservado para los usuarios registrados. Registrate <a href="'.wp_registration_url().'">aquí</a> o <a href="'.wp_login_url(get_permalink()).'">inicia la sesión</a> para poder verlo..</p>';
}
发布评论

评论列表(0)

  1. 暂无评论