timber context filter inside add_shortcode functionWordpress custom post, how to display custom fields on listinginsert multiple shortcodes within a shortcode wordpressFilter to remove p tag from image inside ACF WYSIWYG + TimberTimber: Exclude category methodTimber - extend data to context (WordPress)Using custom functions with TimberTimber get_posts in template/viewWordpress shortcode to get next post in taxonomy returns nothingLoop inside timber twig fileTwig_Error_Syntax for “Unknown filter” with a Twig filter in Timber
Ways of geometrical multiplication
Would a primitive species be able to learn English from reading books alone?
How do I fix the group tension caused by my character stealing and possibly killing without provocation?
Limit max CPU usage SQL SERVER with WSRM
Overlapping circles covering polygon
Can I cause damage to electrical appliances by unplugging them when they are turned on?
When and why was runway 07/25 at Kai Tak removed?
Does the Crossbow Expert feat's extra crossbow attack work with the reaction attack from a Hunter ranger's Giant Killer feature?
Proving an identity involving cross products and coplanar vectors
How do I Interface a PS/2 Keyboard without Modern Techniques?
What does "Scientists rise up against statistical significance" mean? (Comment in Nature)
Personal or impersonal in a technical resume
Can you identify this lizard-like creature I observed in the UK?
Why does the Persian emissary display a string of crowned skulls?
Language involving irrational number is not a CFL
How do you justify more code being written by following clean code practices?
ContourPlot — How do I color by contour curvature?
Air travel with refrigerated insulin
Review your own paper in Mathematics
How many people need to be born every 8 years to sustain population?
Do I have to take mana from my deck or hand when tapping a dual land?
Echo with obfuscation
Grepping string, but include all non-blank lines following each grep match
Identifying "long and narrow" polygons in with PostGIS
timber context filter inside add_shortcode function
Wordpress custom post, how to display custom fields on listinginsert multiple shortcodes within a shortcode wordpressFilter to remove p tag from image inside ACF WYSIWYG + TimberTimber: Exclude category methodTimber - extend data to context (WordPress)Using custom functions with TimberTimber get_posts in template/viewWordpress shortcode to get next post in taxonomy returns nothingLoop inside timber twig fileTwig_Error_Syntax for “Unknown filter” with a Twig filter in Timber
I've been trying to access timber context in add shortcode function but it doesn't seem to work.
My code is
add_action( 'init', array($this, 'create_shortcodes' ) );
public function create_shortcodes()
add_shortcode( 'social_media', array($this, 'social_shortcode') );
public function social_shortcode($atts)
$params = shortcode_atts(array(
'id' => 0
), $atts);
$data = Helpers::create_social_media( $atts['id'], false, true );
add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );
return TimberTimber::compile('social-media.twig', array('data' => $data['content'] ));
public function add_to_context_social_media($context)
echo '<pre style="margin:200px">';
print_r($context);
echo '</pre>';
return $context;
If I add the filter inside the create_shortcodes function it works, but it doesn't isnide the add_shortcode function which also is inside the create_shortcodes function.
Any help will be appreciated.
Thanks
wordpress timber
add a comment |
I've been trying to access timber context in add shortcode function but it doesn't seem to work.
My code is
add_action( 'init', array($this, 'create_shortcodes' ) );
public function create_shortcodes()
add_shortcode( 'social_media', array($this, 'social_shortcode') );
public function social_shortcode($atts)
$params = shortcode_atts(array(
'id' => 0
), $atts);
$data = Helpers::create_social_media( $atts['id'], false, true );
add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );
return TimberTimber::compile('social-media.twig', array('data' => $data['content'] ));
public function add_to_context_social_media($context)
echo '<pre style="margin:200px">';
print_r($context);
echo '</pre>';
return $context;
If I add the filter inside the create_shortcodes function it works, but it doesn't isnide the add_shortcode function which also is inside the create_shortcodes function.
Any help will be appreciated.
Thanks
wordpress timber
add a comment |
I've been trying to access timber context in add shortcode function but it doesn't seem to work.
My code is
add_action( 'init', array($this, 'create_shortcodes' ) );
public function create_shortcodes()
add_shortcode( 'social_media', array($this, 'social_shortcode') );
public function social_shortcode($atts)
$params = shortcode_atts(array(
'id' => 0
), $atts);
$data = Helpers::create_social_media( $atts['id'], false, true );
add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );
return TimberTimber::compile('social-media.twig', array('data' => $data['content'] ));
public function add_to_context_social_media($context)
echo '<pre style="margin:200px">';
print_r($context);
echo '</pre>';
return $context;
If I add the filter inside the create_shortcodes function it works, but it doesn't isnide the add_shortcode function which also is inside the create_shortcodes function.
Any help will be appreciated.
Thanks
wordpress timber
I've been trying to access timber context in add shortcode function but it doesn't seem to work.
My code is
add_action( 'init', array($this, 'create_shortcodes' ) );
public function create_shortcodes()
add_shortcode( 'social_media', array($this, 'social_shortcode') );
public function social_shortcode($atts)
$params = shortcode_atts(array(
'id' => 0
), $atts);
$data = Helpers::create_social_media( $atts['id'], false, true );
add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );
return TimberTimber::compile('social-media.twig', array('data' => $data['content'] ));
public function add_to_context_social_media($context)
echo '<pre style="margin:200px">';
print_r($context);
echo '</pre>';
return $context;
If I add the filter inside the create_shortcodes function it works, but it doesn't isnide the add_shortcode function which also is inside the create_shortcodes function.
Any help will be appreciated.
Thanks
wordpress timber
wordpress timber
edited Feb 6 '18 at 13:40
Raf
asked Feb 6 '18 at 11:20
RafRaf
15219
15219
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Would it be better to render the returned output instead of rendering it inside the shortcode ?
$returned_shortcode = do_shortcode('[your_shortcode]');
return TimberTimber::compile('social-media.twig', array('data' => $returned_shortcode ));
add a comment |
When you use this line
add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );
Then you would need to call Timber::get_context()
for the filter to be applied. However, calls to Timber::get_context()
are cached. This means that if you wanted to use the timber_context
filter, you’d have to do add it before your first call to Timber::get_context()
. If you wanted to use that in a shortcode, you probably already call Timber::get_context()
in the singular or archive PHP template that displays the post’s content.
I guess you could build up the data context for your social-media.twig template like follows:
public function social_shortcode($atts)
$params = shortcode_atts(array(
'id' => 0
), $atts);
// Get cached context.
$context = Timber::get_context();
// Add to context.
$context['data'] = Helpers::create_social_media(
$atts['id'],
false,
true
);
return TimberTimber::compile( 'social-media.twig', $context );
In addition to your custom data
, you would also have the global context available in your Twig file.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48641831%2ftimber-context-filter-inside-add-shortcode-function%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Would it be better to render the returned output instead of rendering it inside the shortcode ?
$returned_shortcode = do_shortcode('[your_shortcode]');
return TimberTimber::compile('social-media.twig', array('data' => $returned_shortcode ));
add a comment |
Would it be better to render the returned output instead of rendering it inside the shortcode ?
$returned_shortcode = do_shortcode('[your_shortcode]');
return TimberTimber::compile('social-media.twig', array('data' => $returned_shortcode ));
add a comment |
Would it be better to render the returned output instead of rendering it inside the shortcode ?
$returned_shortcode = do_shortcode('[your_shortcode]');
return TimberTimber::compile('social-media.twig', array('data' => $returned_shortcode ));
Would it be better to render the returned output instead of rendering it inside the shortcode ?
$returned_shortcode = do_shortcode('[your_shortcode]');
return TimberTimber::compile('social-media.twig', array('data' => $returned_shortcode ));
answered Feb 6 '18 at 20:53
BeeeBeee
1235
1235
add a comment |
add a comment |
When you use this line
add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );
Then you would need to call Timber::get_context()
for the filter to be applied. However, calls to Timber::get_context()
are cached. This means that if you wanted to use the timber_context
filter, you’d have to do add it before your first call to Timber::get_context()
. If you wanted to use that in a shortcode, you probably already call Timber::get_context()
in the singular or archive PHP template that displays the post’s content.
I guess you could build up the data context for your social-media.twig template like follows:
public function social_shortcode($atts)
$params = shortcode_atts(array(
'id' => 0
), $atts);
// Get cached context.
$context = Timber::get_context();
// Add to context.
$context['data'] = Helpers::create_social_media(
$atts['id'],
false,
true
);
return TimberTimber::compile( 'social-media.twig', $context );
In addition to your custom data
, you would also have the global context available in your Twig file.
add a comment |
When you use this line
add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );
Then you would need to call Timber::get_context()
for the filter to be applied. However, calls to Timber::get_context()
are cached. This means that if you wanted to use the timber_context
filter, you’d have to do add it before your first call to Timber::get_context()
. If you wanted to use that in a shortcode, you probably already call Timber::get_context()
in the singular or archive PHP template that displays the post’s content.
I guess you could build up the data context for your social-media.twig template like follows:
public function social_shortcode($atts)
$params = shortcode_atts(array(
'id' => 0
), $atts);
// Get cached context.
$context = Timber::get_context();
// Add to context.
$context['data'] = Helpers::create_social_media(
$atts['id'],
false,
true
);
return TimberTimber::compile( 'social-media.twig', $context );
In addition to your custom data
, you would also have the global context available in your Twig file.
add a comment |
When you use this line
add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );
Then you would need to call Timber::get_context()
for the filter to be applied. However, calls to Timber::get_context()
are cached. This means that if you wanted to use the timber_context
filter, you’d have to do add it before your first call to Timber::get_context()
. If you wanted to use that in a shortcode, you probably already call Timber::get_context()
in the singular or archive PHP template that displays the post’s content.
I guess you could build up the data context for your social-media.twig template like follows:
public function social_shortcode($atts)
$params = shortcode_atts(array(
'id' => 0
), $atts);
// Get cached context.
$context = Timber::get_context();
// Add to context.
$context['data'] = Helpers::create_social_media(
$atts['id'],
false,
true
);
return TimberTimber::compile( 'social-media.twig', $context );
In addition to your custom data
, you would also have the global context available in your Twig file.
When you use this line
add_filter( 'timber_context', array($this, 'add_to_context_social_media'), 11 );
Then you would need to call Timber::get_context()
for the filter to be applied. However, calls to Timber::get_context()
are cached. This means that if you wanted to use the timber_context
filter, you’d have to do add it before your first call to Timber::get_context()
. If you wanted to use that in a shortcode, you probably already call Timber::get_context()
in the singular or archive PHP template that displays the post’s content.
I guess you could build up the data context for your social-media.twig template like follows:
public function social_shortcode($atts)
$params = shortcode_atts(array(
'id' => 0
), $atts);
// Get cached context.
$context = Timber::get_context();
// Add to context.
$context['data'] = Helpers::create_social_media(
$atts['id'],
false,
true
);
return TimberTimber::compile( 'social-media.twig', $context );
In addition to your custom data
, you would also have the global context available in your Twig file.
answered Mar 7 at 21:54
GchtrGchtr
1,47411220
1,47411220
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48641831%2ftimber-context-filter-inside-add-shortcode-function%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown