How to make a rest style plugin?

I got a little piece of code here, but it should/could probably be improved. Create new query_vars Create new rewrite rule Redirect to specific template which then handles your parameters Create new query vars function register_gallery_query_vars($vars) { $vars[] = ‘gallery_id’; $vars[] = ‘image_id’; return $vars; } add_filter(‘query_vars’, ‘register_gallery_query_vars’); Add rewrite rule function custom_rewrite_gallery() { add_rewrite_rule(‘^gallery/([0-9]+)/([0-9]+)/?’, … Read more

Unable to change the location of a file

One problem could be that you’re missing “ ***<img class=”srcimage” src=server-side4.php/>*** Change it to ***<img class=”srcimage” src=”http://example.com/your-path/server-side4.php” />*** Then if that doesn’t fix it, try outputting your variables to see what you’re working with. Make sure that all these values are giving you the results you’re expecting. console.log(base); console.log(jQuery(“#realtime-form”).serialize()); console.log(jQuery(“.preview img”)); If you don’t want … Read more

Adding react app to an existing wordpress website

You need to include scripts and styles properly as it has been done here https://github.com/radekzz/wordpress-react-in-theme add_action( ‘wp_enqueue_scripts’, ‘enqueue_my_react_app’ ); function enqueue_my_react_app(){ foreach( glob( get_template_directory(). ‘/myReactApp/build/static/js/*.js’ ) as $file ) { // $file contains the name and extension of the file $filename = substr($file, strrpos($file, “https://wordpress.stackexchange.com/”) + 1); wp_enqueue_script( $filename, get_template_directory_uri().’/myReactApp/build/static/js/’.$filename); } foreach( glob( get_template_directory(). ‘/myReactApp/build/static/css/*.css’ … Read more

Javascript not working on index.php but it is working on single post’s page

The proper way to enqueue a script is as follows: function mathJax_scripts() { wp_enqueue_script( ‘mathjax-js’, http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML’, array(), ‘2.7.1’, false ); } add_action( ‘wp_enqueue_scripts’, ‘mathJax_scripts’ ); I added the version number (2.7.1) and I flipped the final parameter to ‘false’ – that last parameter asks ‘add script to footer?’, true means yes, false means no. Then … Read more

Carousel Hover Image

I figured it out!! I added this piece of jQuery: <script type=”text/javascript”> <!– $(function() { jQuery(“.photos a”).hover(function() { var offset = $(this).offset(); var id_post = $(this).attr(“id”); jQuery(“.hover”).find(“span[id=”+id_post+”]”).css(“left”, (offset.left-312)+”px”); jQuery(“.hover”).find(“span[id=”+id_post+”]”).show(); }, function() { jQuery(“.hover”).find(“span”).hide(); }) }); //–> </script> and added an additional loop: <div class=”hover”> <?php query_posts( ‘category_name=photos&posts_per_page=-1’ ); ?> <?php if ( have_posts() ) : … Read more

Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)

In general, this function lets you localize your JS strings, but you can also use it to set global JS variables: function set_my_js_var() { // logic here for returning the right JS var $myVar = “Hello World”; return $myVar; } function load_fe_scripts() { wp_enqueue_script( ‘global-js-var’, get_template_directory_uri() . ‘/js/my_file.js’ ); $localize_array = array( ‘my_js_var’ => set_my_js_var() … Read more

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