Using get_option() in JavaScript

Define an array of parameters to be injected into the script: $script_params = array( ‘myWidth’ => get_option(‘my_width’) ); Localize the script via wp_localize_script: wp_localize_script( ‘your-script-handle’, ‘scriptParams’, $script_params ); scriptParams now is a js object you can access from within the script: alert( scriptParams.myWidth ); // the value from the PHP get_option call in the js

Filter specific shortcode output?

There is no filter that I know of that is meant to target individual shortcodes like you want. You can filter attributes with shortcode_atts_{$shortcode} though. You can hijack another shortcode by creating your own callback and registering it with the original shortcode slug. I think that is what you are probably going to need to … Read more

Use AJAX in shortcode

First off, this is very borderline within the scope of WPSE, it at all. Apart from the shortcode to trigger the initial HTML output, this is really just AJAX. Anyhow, that being said, this is how it’s done: The PHP Assuming that the above PHP snippet you supplied is functional, place the following in a … Read more

How to get shortcode’s input values inside a filter?

Using a global variable will work. Here’s a demonstration: function wpse_shortcode_function( $atts ){ // User provided values are stored in $atts. // Default values are passed to shortcode_atts() below. // Merged values are stored in the $a array. $a = shortcode_atts( [ ‘id’ => false, ], $atts ); // Set global variable $value using value … Read more

WordPress plugin shortcode not working

There are a couple of things to check here One: Is your plugin activated. Two: Is your shortcode in your main plugin file. If that code is in another file inside your plugin, did you make sure to include that extra file into your main plugin file Three: Don’t you have any type of error … Read more

shortcodes output before content [duplicate]

Shortcode callbacks have to return, not output. So use the following: function test() { return ‘-TEST-‘; } add_shortcode( ‘testshortcode’, ‘test’ ); More info: http://codex.wordpress.org/Shortcode_API If you have to use echo you can also do it this way(useful if there’s a lot of markup & it’s difficult working with strings)- function test() { ob_start(); echo ‘-TEST-‘; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)