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
|
1 Answer
Reset to default 0You 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>';
}
$content
inreturn do_shortcode( $content );
As a side note, I would strongly recommend wrapping yourif
statement in{}
. Much easier to read. – disinfor Commented Mar 23, 2020 at 15:51