Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SOLVED How to hook filter to component content?
I'm developing plugin for personal purposes.

I want to filter content of a component. I know that I can hook to page content through `add_filter('content', 'fun_name');` but it does not contain component content.

In template component content is returned through `<?php get_component('component-3'); ?>`.

It seems that neither `add_filter('component', 'fun_name');` or `add_filter('component-3', 'fun_name');` work.

How to filter component content?
There is no such a hook exists. There is a function get_component(), but it is really useless because it does not return the component but processes it immediately (should normally be named "exec_component"). Don't waste your time on it, rather create a custom function/plugin instead.

You can execute your function on any action and alter the content of your component:
PHP Code:
add_action('theme-header''modify_component', array('your-component-slug')); 

And the function may look like this:
PHP Code:
function modify_component($id) {
   global $components;

   if(!$components) {
$components = array();
       if(file_exists(GSDATAOTHERPATH.'components.xml')) {
           $data getXML(GSDATAOTHERPATH.'components.xml');
           $components $data->item;
($components as $component) {
       if($component->slug == $id) {
           $newValue 'New component value';
           $component->value $newValue;

Very useful code example, thanks for posting.

More about this here:
Thank you for your reply and useful resources.
in 3.4 I think there is a get component xml or a way to get raw, i would have to look
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix

Users browsing this thread: 1 Guest(s)