New answers tagged

0

No way; shortcode is related to the plugin installed on the website you can't reuse it.


0

I change the array in get_children() and foreach loop with below reference url and code work fine. please check the argument that you have passed also use echo statement like they shown in the example. reference url : https://developer.wordpress.org/reference/functions/get_children/ let me know result or errors $args = array( 'posts_per_page' => 1, ...


0

Use a global and set the value to $atts.


1

Use add_shortcode in your plugin or theme or, if you don't want to add a plugin or modify the theme, use Code Snippets plugin. Your code will look like this: add_shortcode( "your-awesome-unique-shortcode", "wpse376442_your_awesome_shortcode_callback"); function wpse376442_your_awesome_shortcode_callback($atts, $content, $shortcode_tag) { ...


1

Simple solution which worked for me is to just remove paragraph end "</p>" from the beginning of the $content, and paragraph begin "<p>" from the end of the $content. For example with regex like: function fix_paragraphs($content) { $patterns = array('/^<\/p>/i', '/<p>$/i'); return preg_replace($patterns, '',...


0

try my variant: <?php if (!is_user_logged_in()) : ?> <form action="<?=get_home_url(); ?>myaccount" method="POST"> <input type="submit" value="<?php _e('Hello, Client! Click to sign in:', 'theme'); ?>"> </...


1

add_shortcode( 'dashtest', function () { $user_id = get_current_user_id(); $key = 'user_wpc'; $single = true; $user_last = get_user_meta( $user_id, $key, $single ); if ($user_id == 0) { echo 'You are currently not logged in.'; } else { echo do_shortcode('[userwpcode key="'.$user_last.'/edit"]'); } } );


1

Following would be the revised example code which you may want to try. function display_api_response() { $api_url = "https://randletter2020.herokuapp.com"; $response = wp_remote_get($api_url); if ( 200 === wp_remote_retrieve_response_code($response) ) { $body = wp_remote_retrieve_body($response); if ( 'a' === $body ) { ...


0

Ended up creating a plugin for this: https://davidstockdalescrapcode.co.uk/my-plugins


2

esc_html_e() displays (echo) the output, hence it appears at the wrong place. So you should instead use esc_html__() which returns the translated string.


1

You can use a closure for that together with the use keyword. Simple example: $dynamic_value = 4; add_shortcode( 'shortcodename', function( $attributes, $content, $shortcode_name ) use $dynamic_value { return $dynamic_value; } ); See also Passing a parameter to filter and action functions.


0

You can pass an array of attributes ($atts) in the callback function that will run whenever you run add_shortcode(). notice the $user_defined_attributes in the following example: add_shortcode( 'faq', 'process_the_faq_shortcode' ); /** * Process the FAQ Shortcode to build a list of FAQs. * * @since 1.0.0 * * @param array|string $user_defined_attributes ...


1

No there isn't, and it isn't necessary. Post type names are their own unique identifiers. The primary reason there are no numeric IDs is because post types are registered on every page load in PHP, no table exists in the database for them, which means no row IDs. So there is no use for a unique ID that the post name doesn't already accomplish. For this ...


0

This is because output buffers are closed, but they're never opened. Adding this at the beginning of the shortcode will fix things: ob_start();


3

You have a typo in your code (enwhile instead of endwhile) so PHP is complaining because of non-closed while loop. Correct it and everything should be ok.


0

You can test if a post has a particular term assigned to it with the has_term function. E.g. if ( has_term( 'term-slug', 'taxonomy-slug' ) ) { // do stuff } With this you can test if your "post" has a particular "term" ( aka if your "product" has a particular "product_cat" )


0

because I'm not echoing anything in this code. But you are! This code: function smb_function( $atts ) { ?> <div class="social_button_shortcode"><?php Is the same as: function smb_function( $atts ) { echo ' <div class="social_button_shortcode">'; Likewise with the closing div tag at the end. Any form of direct ...


1

There are 2 major bugs here Problem 1: Your shortcode registration is invalid You should be seeing lots of messages about this in your PHP error log add_shortcode('splite', 'splite_article'); There is no function named splite_article, there's a class function but the code didn't tell it to use it. So instead of calling your shortcode function, it generates ...


0

The reason your code only applies to the first table, is because you are only selecting the first input with var number = document.querySelector('.nutrition-table__number'); You need to loop over all your tables, and add an event listener to each. Here is an example of how this could work. The plugin pattern is from https://vanillajstoolkit.com/boilerplates/...


Top 50 recent answers are included