New answers tagged

0

Init your shortcode add_shortcode('shortcode_ald_crp', 'myshortcode_echo_ald_crp'); The function what you want: function myshortcode_echo_ald_crp() { ob_start(); if ( function_exists( 'echo_ald_crp' ) ) echo_ald_crp(); return ob_get_clean(); } you call you shortcode in a post like this: [shortcode_ald_crp] Or into the php code: echo ...


0

Do you mean something like this (untested): // function for your shortcode function shortcode_action($atts) { ob_start(); if ( function_exists( 'echo_ald_crp' ) ) echo_ald_crp(); $content = ob_get_clean(); return $content; } // creates shortcode [shortcodehandle] so change it accordingly add_shortcode( 'shortcodehandle', '...


0

Use isset or empty to check if the user entered href or link. That way your shortcode can support both.


0

function jk_WPSCEX_add_message( $atts ) { $output = '<a href="' . $atts['link'] . '">' . $atts['text'] . '</a>'; return $output; } using the above function shortcode is generated in the form of [jk link="http://jaskokoyn.com" text="Like me on Facebook"] OR For Enclosed type of shortcode: function jk_WPSCEX_add_message( $atts, $content =...


1

If you are targeting class method you need to pass an array where first argument is class instance and second is method name as string. Your add_shortcode line should look like this: add_shortcode($this->short_code_name, array($this, 'do_frontend_shortcode'));


2

Here we consider the question: can post embeds be disabled for all the internal links on a site currently running WordPress 4.5.3? The Short Story If we want to disable post embedding of internal links, but allow it on external sites, then we can use: /** * Disable post embeds for internal links but allow it on external sites */ add_filter( '...


11

We start by adding the custom TinyMCE Button: function add_mce_button_custom_em() { // check user permissions if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) { return; } // check if WYSIWYG is enabled if ( 'true' == get_user_option( 'rich_editing' ) ) { add_filter( '...


1

First off, it's always good to register shortcode during init versus just in your general functions.php file. At the very least add_shortcode() should be in init. Anyway, let's begin! Whenever you use add_shortcode() the first parameter is going to be the name of the shortcode and the 2nd will be the callback function. This means that: [products line="...


0

This is working for me $shortcode = 'book'; $pattern = get_shortcode_regex(); // if shortcode 'book' exists if ( preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches ) && array_key_exists( 2, $matches ) && in_array( $shortcode, $matches[2] ) ) { $shortcode_atts = array_keys($matches[2], $shortcode); // ...


0

Here you go. I think the first problem was calling do_shortcode($content) that gets called by add_shortcode() so it's redundant here. Then I think calling wpautop($content) introduced another problem rather than getting closer to a solution. function articlesection_rs_shortcode($atts, $content) { return '<span itemprop="articleSection">'. $content .'...


1

adding those codes into functions.php (tested in a child theme of Twenty Sixteen) seems to work: add_filter( 'term_description', 'shortcode_unautop' ); add_filter( 'term_description', 'do_shortcode' ); remove_filter( 'pre_term_description', 'wp_filter_kses' );


0

You do not need wp_reset_query() here use wp_reset_postdata() instead cause it's a secondary query and you do not need to reset to the original main query. Never use echo in shortcode, replace line : echo "Nothing to show"; with : $html_out = "Nothing to show"; To get what you want you may use : global $wp_query; $wp_query->current_post It gives ...


0

I actually solved this... here's what you need to do if anyone needs to do something similar: SO, you can't really query a site, but you can query pages on sites... so what I did was make a new page on the site where everything looked good, embed the shortcode, query that page and the content only on the other site. You NEED to have the site switch to that ...


4

Call your shortcode like [span class="foo"/][span class="bar"/][span class="baz"]stuff[/span] You will get your expected result. Wordpress thought your shortcode like


0

Are you sure you want to do this in this manner? Normally a section like this might be written to the page template somehow and not called via the content editor. That being said, this should do what you need: add_shortcode( 'show_xyz_news', 'xyz_news_query' ); function xyz_news_query() { $args = array( 'posts_per_page' => 3, '...


2

You just have to add another element to the array (and then output it): function btn_shortcode( $atts, $content = null ) { $a = shortcode_atts( array( 'class' => 'button', 'href' => '#' ), $atts ); return '<a class="' . esc_attr($a['class']) . '" href="' . esc_attr($a['href']) . '">' . $content . '</a>'; } ...


0

Correct. post__in requires an array but the id parameter in [video-course limit=8 id="418, 1186"] is passed in as a string, so in your shortcode, you would have to parse it into an array in order to use it: if ( !is_array($id) ) { // If $id is not an array (not your default value in your example) // then simultaneously parse it into an array and ...


-1

It's probably best to render the shortcode on output by running it through do_shortcode()


3

It seems that extract() function sets it to false if value is not provided. There might be a better way around it, but I've used workaround as follows function Test($atts) { extract(shortcode_atts(array( 'row' => null ), $atts)); $output = 'false'; if( in_array('row', $atts)) $output = 'true'; return $output; } ...


0

Don't use double quotes (") inside the shortcode, since you are using double quotes to specify the href attribute. The browser thinks your href text ends at position=. Use single quotes instead: href="/reservation/?unitrate=[print_csv position='5']&amp;...I agree with the comments that there is a better way to do this, but I provide a potential answer ...


0

Clouseau are not OOP and you should be able to replace them with any traditional functions in 99% of the cases. As for ajax, your problem is probably in understanding ajax more than with specific mechanics. Ajax is a context free request, the web server has no real reliable way to know from where and under what conditions it was sent, and therefor you have ...


0

not a wp_redirect(), but you could do a JavaScript redirect: window.location="http://www.example.com"; won't do anything if the user has JS disabled, so make sure to provide a link for the redirect.


6

Shortcode functions are only called when the content of the visual editor is processed and displayed, so nothing in your shortcode function will run early enough. Have a look at the has_shortcode function. If you hook in early enough to send headers and late enough for the query to be set up you can check if the content contains your shortcode and ...



Top 50 recent answers are included