Hot answers tagged

5

Is it Ok? Yes! Is it Optimal? No What Would Be Better? Shortcodes map on to PHP functions, so why not cut out the middle man and go straight to the original function? Are there any other downsides? Yes! That shortcode had to come from somewhere, now you have a dependency, maybe the plugin that has the shortcode gets deactivated, who knows Are There ...


3

I think you could get around this by pre-running the shortcodes on the page by applying the content filters before the header is output. This should allow any internal shortcodes run inside the included post to add any action hooks properly and thus any needed stylesheets/resources. add_action('wp_loaded','maybe_prerun_shortcodes'); function ...


3

This may be a silly idea, but it might work: 1 Let your shortcode explode to an iframe with a custom query_var (tutorial). Like this: <iframe src="http://www.example.com/?p=123&my_query_var=content_only"></iframe> 2 In your single.php detect the query_var and in that case skip visual header, sidebars, footer - anything not connected to ...


3

I tested following code and it worked just fine for me: function my_name_shortcode( $atts ) { return "<h3>PRASAD</h3>"; } add_shortcode( 'name', 'my_name_shortcode' ); add_filter( "the_excerpt_rss", "do_shortcode" ); The result can be seen in below screenshot.


2

Well, yes, you can do that: //replace live edited content to display html editor.on('BeforeSetcontent', function(event){ event.content = tinymce_to_html( event.content ); }); //Transform your html content to raw content editor.on('GetContent', function(event){ event.content = html_to_tinymce( event.content ); }); Let's explain that: Under the ...


2

The closest to a reference technique in core would be [gallery] shortcode. If you look at the source of implementing gallery_shortcode() function you'll see that it: Generates instance number (so multiple shortcodes can be distinguished). Outputs dynamic CSS inline into a page source, for each instance. I wouldn't consider it particularly neat solution, ...


2

Load visual compose css function get_visual_composer_style($id) { return '<style>' . get_post_meta( $id, '_wpb_shortcodes_custom_css', true ) . '</style>'; } Load css based on shortcode function custom_shortcode_scripts() { global $post; if( is_a( $post, 'WP_Post' ) && has_shortcode( ...


1

Shortcodes done that way is a less sinister relative of eval. It is ok if you intend to give a user an option but not an acceptable coding practice. When activating a function that way you lose three things Code readability. What is exactly you intended to do there? I will not be able to guess it without looking at the implementation of the shortcode ...


1

A shortcode is a placeholder for a PHP callback. As placeholder, it is intended to be used where PHP can not be used directly. Additionally, do_shortcode() will do a regex in the passed string looking for all registered shortcodes, which is not appropiate from a performance point of view if you just want to execute one shortocode, not to look for all ...


1

get_the_content doesn't apply all of the filters that the_content runs before outputting the result. You can fix this by simply using: <?php the_content(); ?> in place of: <?php echo $content; ?> If you look at the source for the_content, you'll see the extra step it performs on what is returned from get_the_content.


1

the_content is usually "executed" in the context of a loop when all relevant global data is set. You should try to mimic it by using code like function get_page_content(){ global $post; $id = $_REQUEST['id']; $post = get_page($id); setup_postdata($post); echo apply_filters('the_content', $post->post_content); //echo ...


1

First, don't echo your php, but assemble everything in a string, let's say $titlestring. Next, make this string available for access by the javascript (the slug is the one you used to register the script): $params = array ( 'titlestring' => $titlestring, ); wp_localize_script ('your-script-slug', 'IframeTitle', $params); Finally, access the ...


1

wp_login_form is completely separate from wp-login.php - the login_form hook only applies to the latter. For the former, you've got three filters at your disposal: login_form_top - return HTML to be injected right after the opening <form /> tag login_form_middle - return HTML to be injected between the password field and the remember me/submit field ...


1

Shortcodes are backend stuff, so you can't just change values of shortcodes itself in editor with jQuery, the thing you can do is to call both shortcodes, hide one of them, and on click show him and hide other one. It all depends what do you want to do, but one of the option is to hide them like this and in this case use classes also with display:none



Only top voted, non community-wiki answers of a minimum length are eligible