How to add “get_theme_mod” inside a shortcode?

I would comment, but lack the pointage… You seem to be on the right track: I see that your shortcode callback and the function are named differently: (f_gallery_shortcode / function_gallery_shortcode). Try this: add_shortcode( ‘ui_gallery’,’function_gallery_shortcode’ ); function function_gallery_shortcode(){ $dynamic_h1 = “<h1>” . get_theme_mod(‘dynamich1’) . “</h1>”; return $dynamic_h1; } now using [ui_gallery] in your posts, should return … Read more

How to dynamically add wordpress shortcodes

Assuming the $row->internalFunction is a function, or the name of a function which already exists, then you can do something like so: foreach ( $dbQuery as $row ) { add_shortcode( $row->formName, $row->internalFunction ); } So if the formName (shortcode tag) is foo and internalFunction is foo_func, then [foo] will be handled by the foo_func() function: … Read more

Add shortcode with open close function

To change the functionality of a shortcode you must first remove_shortcode( ‘shortcode_name’ ); where shortcode name is the name of the shortcode. Add the shortcode back with your NEW function. A simple example to follow what you might be needing: remove_shortcode( ‘mybutton’ ); add_shortcode( ‘mybutton’, ‘my_shortcode_function’ ); my_shortcode_function( $atts, $content = “” ) { return … Read more

Gutenberg Shortcode Fail

The shortcode doesn’t work because it’s wrapped inside quotes — “[current_user]”. But a better explanation is, because it’s in a HTML attribute. And it’s not a Gutenberg or the block editor problem; even with <?php echo do_shortcode( ‘<input name=”name” value=”[current_user]” type=”hidden”>’ ); ?>, the shortcode would still remain as-is. Because shortcodes in HTML attributes are … Read more

How to create a shortcode with html and php code

You can use PHPs output buffering, using ob_start to turn on the buffering and ob_get_clean to get and delete the current output buffering. So going by your code it would look like this function blogPost(){ ob_start(); ?> <section class=”blog container spacer”> <article class=”blog__list”> <div class=”glide-blog”> <div class=”glide__arrows” data-glide-el=”controls”> <button class=”glide__arrow glide__arrow–left” data-glide-dir=”<“>&lt;</button> <button class=”glide__arrow glide__arrow–right” … Read more

How can i share codes on my blog?

I’d suggest using Syntax Highlighter Evolved. It’s by Viper007Bond. You can use it like this: [sourcecode lang=”php”] <?php echo ‘Hello World!’; ?> [/sourcecode] Or even like this: [php] <?php echo ‘Hello World!’; ?> [/php] A screenshot: EDIT An example of how you could do the backticks method that SE uses: function wpse13653_content( $content ){ return … Read more

Replacement for gallery_shortcode function not taking all attributes

<?php function modified_post_gallery( $blank = NULL, $attr ) { echo ‘<pre>’; print_r( $attr ); echo ‘</pre>’; } add_filter( ‘post_gallery’, ‘modified_post_gallery’, 10, 2); ?> In media.php it shows the filter like this: // Allow plugins/themes to override the default gallery template. $output = apply_filters(‘post_gallery’, ”, $attr); Its passing two variables not one and $attr is on … Read more

Insert PHP code via shortcode?

$current_user isn’t declared in the scope of that function. You’d want to modify the code to be more like this: function get_form($atts) { $current_user = wp_get_current_user(); return ‘<form method=”post” action=””> <input type=”input” name=”myinput” value=””></input> <input type=”hidden” name=”myvar” value=”‘ . $current_user->ID . ‘”> </form>’; } add_shortcode(‘myshortcode’, ‘get_form’);

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