New answers tagged

0

In case anyone needs it, here was my final code: <?php //LIST ALL DOCUMENTS add_shortcode('listDocs','listDocs'); function listDocs(){ $params = array( 'paged' => get_query_var('paged', 1), 'posts_per_page' => 25, 'post_type' => 'product', 'product_cat' => 'documents' ); $wc_query = new WP_Query($...


1

The main issue in your code is the following part, whereby you set the attribute source to text which means (after the block/post is saved) the editor will read the value from the inner text of the div returned by your save function: attributes: { content: { type: "string", source: "text", // this shouldn't be "...


0

Even though this is specific for OceanWP, the solution is plain Wordpress. Add these two lines to the end of your functions.php to render the shortcodes in both the_excerpt() and get_the_excerpt(). add_filter( 'the_excerpt', 'do_shortcode' ); add_filter('get_the_excerpt', 'do_shortcode');


0

I know this years too late, but just in case anybody encounters this again, you can use this code to be able include a class with your shortcode and its return value. I modified it with the corresponding answers before in here. function print_menu_shortcode($atts=[], $content = null) { $shortcode_atts = shortcode_atts([ 'name' => '', 'class' => '' ]...


1

You made error, you made checks on the value which were null, i compile your code and made changes, here is the code it will help you. function wp_change_namecar( $atts, $content = null ) { if (is_user_logged_in()) { $user_id = get_current_user_id(); $userval =$_POST['cars']; //how to define that it is the value of the form? if ...


0

If you want the excerpt to run the same filters as the posts have, you can add this to your functions.php. add_filter( 'get_the_excerpt', 'get_the_content', 5 ); Keep in mind, that your shortcode might be considered one word when it comes to any setting that limits the excerpt to a certain number of words. Thus, if your shortcode prints out 10 words, and ...


0

If you want the excerpt to run shortcodes, you can add this to your functions.php add_filter( 'the_excerpt', 'do_shortcode' ); add_filter('get_the_excerpt', 'do_shortcode');


2

There are a few to do this: Using double quotes Don't forget to escape the double quotes inside the string. global $post; echo do_shortcode("[sc name=\"$post->post_name\"]"); Using sigle quotes global $post; echo do_shortcode("[sc name='$post->post_name']"); Using sprintf global $post; echo do_shortcode( sprintf('[sc ...


0

Use it like this, this defined('REST_REQUEST') will help you to disable running on the backend gutenberg block editor function generate_new_member_form() { if(defined('REST_REQUEST')) return; ob_start(); ?> // a form // to generate this form there is some code that uses objects or functions // only available in the front end <?php ...


2

There is no definitive way of doing that in WordPress, but here are some options for you: Use a global variable to store the reference list, i.e. the content as in [ref]content here[/ref]. But I personally don't recommend and wouldn't be using global variable. Use a custom PHP class and add the shortcode functions as methods in that class, then use a ...


1

Can you help me identify what the problem is and how can I prevent this? Where is this request coming from? The shortcode is only processed on the frontend. As far as the block editor is concerned the URL specified is [picsum] which is an unprocessed shortcode. There is no simple fix to this, and making it work will require extensive and continuous ...


0

Simple JavaScript solution: Shortcode: [js_logout] functions.php: add_shortcode('js_logout', 'js_logout'); function js_logout() { // redirect to home $logout_url = html_entity_decode(wp_logout_url(home_url())); return '<p>' . __('If you are not redirected automatically, click here:') . ' <a href="' . $logout_url . '">...


Top 50 recent answers are included