Überspringen zu Hauptinhalt

Simple Shortcode

Bonus tip: If you are using the great total theme there are a couple of basic shortcodes that it comes with. You might find them useful to adapt or change. Just have a look in this folder: „/wp-content/plugins/total-theme-core/inc/shortcodes

Simple one Tag Example [shortcode ]

// Do something
add_shortcode( 'media_url', 'media_url_render' );
function media_url_render($atts, $content, $tag) {
	
	global $post;
	$link = get_post_meta( $post->ID, 'media_link_url', true );
	
	return $link;
}

And a simple version with two arguments

// Add Shortcode
function myprefix_count_post_terms( $atts ) {
 
// Attributes
$atts = shortcode_atts(
array(
'post_id' => '',
'taxonomy' => '',
),
$atts
);
 
$terms = wp_get_post_terms( $atts['post_id'], $atts['taxonomy']);
return count($terms);
 
}
 
add_shortcode( 'myprefix_count_post_terms', 'myprefix_count_post_terms' );
//use like [count_post_terms post_id='[myprefix_count_post_terms]' taxonomy='category']

Dieser Beitrag hat 0 Kommentare

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

An den Anfang scrollen