Posts: 210
Threads: 15
Joined: Feb 2013
i want to build a simple plugin
and i want to load it when a placeholder will be simple: (%name_of_placeholder%)
how to do it ?
when this placeholder will be in the content.. i want to load a php file (include) with this script..
I know that for programmers that question will be funny ... but I do not know enough about php to solve this problem ...
I was looking for:
http://get-simple.info/wiki/plugins:creation
but not found an answer
can someone help?
Posts: 6,266
Threads: 181
Joined: Sep 2011
Content filter use a regular expression to replace.
There is probably some code floating around the forums.
Posts: 210
Threads: 15
Joined: Feb 2013
i'm workin on it.. but i still have a errors...
PHP Code:
add_filter('content', 'sm_filter');
function sm_filter($content) {
if (preg_match('/\(%\s*kontakt-pl\s*%\)/', $content)) {
$replacement = generate_output();
$content = preg_replace('/\(%\s*kontakt-pl\s*%\)/', $replacement, $content);
}
return $content;
}
?>
<?php function generate_output() {?>
testing
<?php } ?>
when i use this in content area like (%kontakt-pl %)
i have a "testing" on content area on cms...
in back end is
PHP Code:
I'm trying to show here
/// here conact
(% kontakt-pl %)
/// here contact
but in front-end (template) i get:
PHP Code:
testing
I'm trying to show here
/// here conact
/// here contact
can anyone help ?
Posts: 1,108
Threads: 70
Joined: Aug 2009
Posts: 1,108
Threads: 70
Joined: Aug 2009
Put this in your themes functions.php file:
Code:
function addKontakt($atts, $content = null){
// add any parameters here, remove if not needed.
extract(shortcode_atts(array(
"class" => null,
"id" => null
), $atts));
// params will be available as variables $class, $id etc...
// just return your html code here.
return 'Your contact form here';
}
add_shortcode('kontakt-pl','addKontakt', '[kontakt-pl /]');
Posts: 210
Threads: 15
Joined: Feb 2013
(2014-05-26, 20:23:40)n00dles101 Wrote: Put this in your themes functions.php file:
Code:
function addKontakt($atts, $content = null){
// add any parameters here, remove if not needed.
extract(shortcode_atts(array(
"class" => null,
"id" => null
), $atts));
// params will be available as variables $class, $id etc...
// just return your html code here.
return 'Your contact form here';
}
add_shortcode('kontakt-pl','addKontakt', '[kontakt-pl /]');
thank You very much n00dles101, but i'm searching a meethood to do it with own plugin..
I know that may scare you is that I can not write such a function ... and I want make a new plugin .. but I want to try.
difference is when i write:
PHP Code:
function sm_filter($content) {
if (preg_match('/\(%\s*kontakt-pl\s*%\)/', $content)) {
$replacement = 'testing';
$content = preg_replace('/\(%\s*kontakt-pl\s*%\)/', $replacement, $content);
}
return $content;
}
it's work great...
but when i want to get functionin:
$replacement = generate_output();
it's always on top:
PHP Code:
testing
I'm trying to show here
/// here conact
/// here contact
Posts: 1,108
Threads: 70
Joined: Aug 2009
whats the generate_output() code?
looks like its echo'ing the output rather than returning...
Posts: 210
Threads: 15
Joined: Feb 2013
(2014-05-26, 22:48:50)n00dles101 Wrote: whats the generate_output() code?
looks like its echo'ing the output rather than returning...
PHP Code:
<?php function generate_output() {?>
testing
<?php } ?>
i want to change a string to function ... to enter the values in it .. and html + php code
Posts: 1,108
Threads: 70
Joined: Aug 2009
yeah, it's echo'ing the response.
change it to
Code:
<?php function generate_output() {
return "testing";
} ?>
and it should work.
Posts: 210
Threads: 15
Joined: Feb 2013