Using shortcode content with nested shortcode

You don’t have to use do_shortcode inside your shortcode callback function. But if you don’t do this, then you won’t be able to nest shortcodes, so other shortcodes added on the site won’t work inside it. Let’s say your shortcode callback looks like this: function a_shortcode($atts = [], $content = null) { //use content here, … Read more

Stop post being published

wp_die(); will run AFTER the post is published. You are checking whether the post is published or not, which means the post is already published, what’s done is done. You can update to post status from published to draft instead of using wp_die();. The following code will do it: function check_post_limit( $ID, $post ) { … Read more

How to insert a record by clicking on the link using AJAX

If this is your request data for an AJAX POST: data: { action: ‘gs_order’, nonce_data: ajax_vars.nonce, product_groups: $(this).data(“pgid”), products: $(this).data(“pid”) }, Then you access product_groups and products like this: $data = [ ‘product_groups’ => $_POST[‘product_groups’], ‘products’ => $_POST[‘products’], ]; Just make sure you sanitize and escape the data as required. If they’re going to be … Read more

Gutenberg: How to check if a block is used in a paginated post?

The solution is simple: has_block( ‘simpetoc/toc, $YOUR_POSTS_CONTENT_OR_POST_ID ) https://developer.wordpress.org/reference/functions/has_block/ has_block( string $block_name, int|string|WP_Post|null $post = null ) There is no need to render the blocks to build a table of contents, nor should you do it that way. Note that your current approach breaks user defined HTML anchors and doesn’t account for headings in nested … Read more

How to define a callback for an URI?

You can use add_feed( $url, $callback ). Despite its name it sends a text/html Content-Type. Basic example: add_action( ‘init’, ‘wpse_50841_register_extra_page’ ); function wpse_50841_register_extra_page() { add_feed( ‘wpse50841’, ‘wpse_50841_callback’ ); } function wpse_50841_callback() { print ‘<p>It works!</p>’; } Visit the permalink settings page once to refresh the rewrite cache, and go to example.com/wpse50841/ or example.com/?feed=wpse50841 to see … Read more

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