Skip to content

Commit edbcd40

Browse files
Now supporting short code snippets.
1 parent 3c5cff4 commit edbcd40

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

library/App.php

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function __construct()
3535
new \Municipio\Content\CustomPostType();
3636
new \Municipio\Content\CustomTaxonomy();
3737
new \Municipio\Content\PostFilters();
38+
new \Municipio\Content\ShortCode();
3839

3940
/**
4041
* Widget

library/Content/ShortCode.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Municipio\Content;
4+
5+
class ShortCode
6+
{
7+
public function __construct()
8+
{
9+
add_action('init', array($this, 'registerShortCode'));
10+
}
11+
12+
public function registerShortCode()
13+
{
14+
add_shortcode('meta', array($this,'displayMetaValue'));
15+
}
16+
17+
public function displayMetaValue($atts, $content = "")
18+
{
19+
//Default value
20+
extract(shortcode_atts(array(
21+
'key' => ''
22+
), $atts));
23+
24+
//Get field with formatting if exits
25+
if (function_exists('get_field')) {
26+
return get_field($key);
27+
} else {
28+
global $post;
29+
return get_post_meta($post->ID, $key);
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)