Created
May 27, 2021 11:39
-
-
Save nextab/1170afb98a8325b7e5edd0553f7fb01e to your computer and use it in GitHub Desktop.
Getting started with creating your own custom shortcodes in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function output_my_custom_field($atts, $content = null) { | |
$a = shortcode_atts([ | |
"field" => "_my_custom_field_name", | |
"title" => "Videodauer:", | |
"class" => "custom_field_value_wrapper", | |
], $atts); | |
$return_string = ''; | |
if(get_post_meta(get_the_ID(), $a["field"], true) != '') { | |
$my_custom_field_value = get_post_meta(get_the_ID(), $a["field"], true); | |
$return_string = '<div class="' . $a["class"] . '"><strong>' . $a["title"] . '</strong> ' . $my_custom_field_value . '</div>'; | |
} | |
return $return_string; | |
} | |
add_shortcode('my_custom_field_value', 'output_my_custom_field'); | |
/* Anwendung: | |
[my_custom_field_value field="_my_custom_field_name"] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment