Acessar atributo de fora shortcode wordpress
I am new to object orientation and am trying to create a shortcode with object orientation techniques so that it is possible to access the link_utm attribute in a template file from the outside. But the attribute where I put it in the shortcode is not working and the output is what I defined in the parameter in the shortcode. How to access this attribute from outside? Below what I have achieved so far.
The output of the shortcode with the attributes is like this: [youlike id_post=’6059,73862′ link_utm=’?utm_campaign=test’]
Class Code
class Shortcode {
public $attLink = [];
public function __construct( $utm = '?utm_campaign=recirculacao' ) {
$this->attLink = $utm;
add_shortcode('youlike', array($this, 'youCanLike'));
}
public function youCanLike( $atts ) {
ob_start();
$value = shortcode_atts( array(
'id_post' => '',
'link_utm' => '',
), $atts );
// Checa se existe o valor setado antes de continuar para eliminar bugs
if ( !$value ['id_post'] )
return false;
$post_ids_array = explode(',', $value['id_post']);
$post_current = get_queried_object_id();
$exclude = array( $post_current );
$include = $post_ids_array;
$args = array(
'ignore_sticky_posts' => true, // Performance
'no_found_rows' => true, // Performance
'post__in' => array_diff( $include, $exclude ),
'orderby' => 'date',
'order' => 'DESC'
);
get_template_part( 'global-templates/blocks/block', 'you-can-like', $args );
return ob_get_clean();
}
}
$shortcode = new Shortcode();
Link output in the template file
<a href = "<?php the_permalink(); ?><?php $linkUTM = new Shortcode();echo $linkUTM->attLink; ?>"
Leave an answer
You must login or register to add a new answer .