Creating own shortcode – echoeing php variable based on JS variable

You can’t add logic for changing in that way. You need react on user “front-end” event with js. Also this construction will work wrong: document.getElementById(\”form\”).innerHTML = \”[contact-form-7 id=\”formId\”]\”; Will be always print [contact-form-7 id=\”formId\”], because js can’t do_shortcode function itself. If you wanna make it simple(without ajax process) you need: 1) Print all forms with … Read more

Displaying Hierarchical custom taxonomy

If you want to sort your terms by hierarchy, you can use wp_get_post_terms() instead. It’s usage is similar to get_the_term_list(). Take a look at this simple example: wp_get_post_terms( $post->ID, $taxonomy->name, array( ‘orderby’ => ‘term_id’ ) ); I think we can safely assume that the parent will mostly have a lower ID of its childs (if … Read more

How to add condition in wordpress loop? [closed]

You don’t even need to write a conditional. This can be done by CSS. Let’s have a simple example. Assuming your post’s structure is like this: <div class=”container-class”> <p> <img src=”https://wordpress.stackexchange.com/questions/275291/some-path”/> Some text </p> </div> You can set a rule to float the first image to left, and the second one to right: .container-class img{ … Read more

Using plugin functions/methods within templates

Premature optimization is the root of all evil (ok, waste of programing time). Why would you care how many times a function is called? it is not like the memory or CPU is getting “weaker” by overusing it. It is more important that the code you produce will be self documenting as much as possible … Read more

Pass php dynamic variable to shortcode

I see a few errors in your code… on the html, there was no quotation in front of variable on the php you say you were calling the short code [modifycontent] but by your php you should have been using [mc]. All the same, here’s how I would do it: function modifycontent ($atts, $content = … Read more

Post + form + action + results on the same page

Use this code <?php if(isset($_REQUEST[‘submit_btn’])) { echo “<div>”; $name = $_POST[“names”]; echo “</div>”; $ins=”insert into tablename (fieldname)values(‘$name’) “; $conn->query($ins); ?> <script> alert(‘inserted successfully’); </script> <?php $sel=”select * from tablename”; $r=$conn->query($sel); while($u=$r->fetch_object()) { echo $u->fieldname; } } ?> <form action=”” method=”POST”> <input type=”text” name=”names” id=”names”> <input type=”submit” value=”submit” name=”submit_btn”> </form> Hope this will help you