Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a plugin which uses this shortcode: [daisy]

And the html output of this shortcode is : <a class="clickable">Click Here</a>

Plugin is working perfect if I use the shortcode to trigger the plugin. It works with this also: <?php echo do_shortcode('[daisy]'); ?>

Normally it should work also with the <a class="clickable">Click Here</a> but it's not working, the link appears but if I click on it nothing happens.

I want to use the html output because my website is using a lot of javascript for displaying html content I cannot use php shortcodes inside javascript/jquery functions.

So, do you have any suggestions for this issue? Because I think the shortcode should work also with the html output which triggers that plugin (in my case is a contact form popup) Thanks! Later edit: This is the javascript which triggers the plugin:

<script type="text/javascript">
$(document).ready(function(){
    // Init Plugin
    $(".clickable").contactpopup({
        'style' : '<?php echo $wp_cpup_theme; ?>',
        'bgcolor' : '<?php echo $wp_cpup_color; ?>',
        'formelement' : '#Form_PopContactUs',
        'effect' : '<?php echo $wp_cpup_effect; ?>',
        'header' : '<?php echo $wp_cpup_popup_title; ?>'
    });
});

share|improve this question
    
Is this a plugin you wrote or one from someone else? –  Pippin Sep 1 '12 at 14:54
    
from someone else... –  agis Sep 1 '12 at 17:03
    
Can you please tell us what plugin it is? Most likely it doesn't work because the short code triggers some javascript to load, which doesn't happen when just using the HTML. –  Pippin Sep 1 '12 at 17:08
    
this is the plugin, and yes I think it triggers some javascript, so is impossible to use just the html of the shortcode? –  agis Sep 1 '12 at 17:27
1  
Ugh, there is a lot wrong with that plugin. In this case, with the way it is built, you will not be able to use it with just the HTML, not unless you rewrite half the plugin to begin with. Sorry. –  Pippin Sep 2 '12 at 2:14

1 Answer 1

up vote 0 down vote accepted

If you open the plugin file and find where the function add_shortcode('daisy','someotherfunction'); is, then you could simply call that function that the shortcode is pointing too.

This code could be placed as follows in a plugin or the functions.php file of your theme:

add_action( 'admin_init', 'daisy_fun' );

function daisy_fun(){
?>
        <script type="text/javascript" defer="defer">
                  jQuery(document).ready(function(){
                        var daisyLink = '<?php echo wp_contact_popup_short_code_handler(); ?>';
                  });
        </script>
<?php
}
share|improve this answer
    
Yes, but as far as I know this is impossible, because you cannot put php function inside jquery because php is a server-side language –  agis Sep 1 '12 at 18:35
    
You should always use jQuery in noConflict mode when using it in WordPress. So use jQuery(document).ready(function($){, otherwise it will result in conflicts. –  Pippin Sep 1 '12 at 19:42
    
In regards to using PHP in JS, yes, you can do it, but only if the JS is placed inline within a PHP file. –  Pippin Sep 1 '12 at 19:43
    
Could you please give me an example of how can I do this in my scenario? Thank you ! –  agis Sep 1 '12 at 20:14
    
I changed the $ into jQuery. But I do want to note that when using a $, I always surround my script with (function ($) {})(jQuery); –  Douglas.Sesar Sep 2 '12 at 19:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.