Tag Info

New answers tagged

1

The Wordpress API documents this very thoroughly. Check it out here. And if you are feeling lazy, here is a custom generator. If you have a specific question beyond that, comment below.


0

First Question: Solved by copying and modifying the "archive-product.php" template file. if(is_product_tag(array('audio'))) : include 'archive-product-audio.php'; // includes custom loop else: // default archive loop endif; Second Question: Solved by simply filtering the Recent Products shortcode via "function.php". ...


0

I wanted to follow-up on this. For some reason, the $audio variable was coming up blank. I used the $atts["mp3"] value and searched the DB to find the media ID, which I then used to grab meta data based on the answer provided by charlenemasters


2

What I always do is, I search the files... So I use the "Search in files"-function in Notepad++ (which I am using) and limit the search to the directory, where I think, I will find what I am looking for. So, probably, you know already the plugins directory. You enter this information into the folder input line e.g.: ...


0

Here's what I've done:created a shortcode where I do [myplugin language="fr" id="5"][myplugin language="us" id="8"] and then, when this page is called, it calls myplugin twice. If it's not on the right page, my plugin returns nothing. So, when this page is called: if it's on a domain like "mydomain.fr" I just call do_shortcode("othershortcode 5") if it's ...


0

Maybe I misunderstand what you are doing, and I apologize if that is the case, but... It looks like you are returning content if the post DOES NOT already have one, which looks backward to me based on my understanding of your problem. It looks like you are trying to execute a broken (incomplete) shortcode. I misunderstood the original question but ...


0

So I found my answer in the codex. content_save_pre() is my friend. Here is the usage: function my_sanitize_content( $content ) { return do_shortcode($content); } add_filter( 'content_save_pre' , 'my_sanitize_content' , 10, 1); Haven't tried it yet, it should work I suppose.


1

I'm not quite sure what you want to do as frankly, your terminology is a bit scrambled, and you example shortcode is also quite a mess. Before I start, you should start of by checking the following very important links Shortcode API WP_Query You should first start of by defining your attributes (and their defaults) which you need to use and pass to the ...


1

If I enter this shortcode: [download url="http://example.com"]Download[/download] it works fine. But you have to enter the link text as content yourself. You might have missed that, the way I read your question. Your [demo]-Shortcode throughs an error. To see this, you need to have WP_DEBUG set to true: Notice: Undefined variable: func in ...


0

@see https://codex.wordpress.org/Function_Reference/do_shortcode Searches content for shortcodes and filters shortcodes through their hooks: echo do_shortcode( get_post_meta( THE_ID_OF_YOUR_POST, THE_NAME_OF_YOUR_CUSTOM_FIELD, true ) );


1

Using the the_posts filter: Here's one idea using the the_posts filter, that fires before setup_postdata() is activated: /** * Replace [nextpage] with <!--nextpage--> through the 'the_posts' filter. * * @see http://wordpress.stackexchange.com/a/183980/26350 */ ! is_admin() && add_filter( 'the_posts', function( $posts ) { $posts = ...


0

This is frustrating issue as I can't depend on the content editors to be savvy enough with Wordpress / HTML to understand how the text they input will be parsed... --EDIT-- Having thought of this a bit more I have reconsidered my earlier answer. HTML5+ comes with the Tidy extension, if you are able to use this on your server then the following will work: ...


2

Untested (and can't test right now) but you ought to be able to add attributes with a filter... something like: function test_sc($atts,$content) { // echo 'test_sc'; $atts = shortcode_atts( array( 'foo' => 'no foo', 'bar' => 'default bar', ), $atts, 'testsc' ); // var_dump($atts); } ...


0

You can add any default content you like, but I don't know of a way of doing it just for Pages (the following will apply to both Pages and Posts): add_filter( 'default_content', 'my_default_post_content' ); function my_default_post_content( $content ) { $content = "Hello World!"; return $content; } (place this in your functions.php file)


0

I think, basically your question is, how to query posts of a custom post type in a shortcode. You should have a look into the WP_Query section of WordPress: https://codex.wordpress.org/Class_Reference/WP_Query In my example code I create a shortcode, which shows the title of the latest published posts of the type 'my-custom-post-type': <?php ...


0

Found a solution here: function get_the_content_with_formatting ($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') { $content = get_the_content($more_link_text, $stripteaser, $more_file); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]&gt;', $content); return $content; }


1

get_the_content() returns unfiltered content, and using a shortcode you cannot use the_content() to return filtered content as you cannot echo inside a shortcode. Your best option here will be is to applying the_content filters to get_the_content(), something like: apply_filters( 'the_content', get_the_content() ); EDIT Exact usage, replace $output .= ...


-1

Neither wp_enqueue_style() nor wp_register_style() have a parameter to allow them to be loaded in the head, rather than the footer, as their script counterparts do. The only solution is to have some of your CSS (or all of it - which would be bad) inside a style tag inside head, added with the wp_head action hook. I used this technique for a while but at some ...


1

I haven't looked in detail at your code, but what strikes me is your open_csv method. You have the following lines return $attributes['file']; return $attributes['type']; As your method currently stands, it stops and returns the value of file right after setting the attributes. Here is what return does in php If called from within a function, theĀ ...


0

You can hook into an action after the main query has run and determine if you need to load your styles and scripts. add_action('template_include', 'custom_template_include'); function custom_template_include($template) { if (is_single() || is_page()) { global $post; if (has_shortcode($post->post_content, 'your_short_code')) { ...


1

The do_shortcode function runs on the the_content hook: 402 403 add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop() https://core.trac.wordpress.org/browser/tags/4.1.1/src/wp-includes/shortcodes.php#L403 So, without seeing your theme code I am going to guess that your theme's archive page is written in such a way that the ...


0

Okay, so found the solution (sorry for the delay) I had to put this: // Add Shortcode function city_name() { global $current_cityinfo; return ' '.$current_cityinfo['cityname']; } add_shortcode( 'city name', 'city_name' );


0

Use a double third brackets then. In visual editor: [[my-shortcode]] To show shortcode as a code, in HTML/Text mode: <code>[[my-shortcode]]</code> And you can even write anything with a third bracket in this way: Do something [[once]] and go... *suggested by SergeyBiryukov


1

It seems that you might have a lot of these .csv files. I would suggest to use only one attribute and then passing the appropriate name to that attribute or the prefix of the file name and then building the file name from there. You can try one of the following (I have not done any verification, you will propbably check that the attribute is not empty and ...


1

You could just echo do_shortcode( $content ); Function Reference/do shortcode


1

As I already stated in comments, extract() should never be used. It was removed from core and the codex for very specific reasons and the use there of is strictly not recommended in future applications and functions. Please see trac ticket #22400 for complete details. As stated before, the codex was also updated accordingly, so you can look at the examples ...


0

You should be passing the 'cityname' to your function: function get_city_name($cityname) { return $cityname; } add_shortcode( 'city-name', 'get_city_name' ); Your shortcode would then look like: [city-name cityname="London"] chances are that your function will return an array, but this should help you move forward


1

You need to get $current_cityinfo first. As in: $current_cityinfo = get_option('current_cityinfo'); Or add this code: global $current_cityinfo; above your return line.


-1

The $atts don't extract automatic, try this before call global $post extract(shortcode_atts(array( 'field' => '',//#Default value or null ), $atts)); This code extract $atts to single variables, see more in Codex.


0

There are multiple solutions: Use CSS for post images: .post img { height: 300px; width: auto; } Use a custom thumbnail size. Either in Settings -> Media or use a third-party plugin to generate them. Another way would be to code your own: function custom_image_sizes() { add_theme_support('post-thumbnails'); add_image_size('breaking-news', 9999, ...


0

The output from a shortcode should be returned, not echoed. Echoing output in a shortcode will have unexpected output like you are seeing. the_widget() echos its output which is causing the issue. Unfortunately there is no similar function for returning the wdget output. Luckily you can make use of a output buffer to overcome this issue. You can try ...


0

Is a plugin out of the question? Seems like that would be the exact solution to your problem.


1

Your output is expected, but before I come to the solution and why's, you have a couple of issues here You are either using query_posts or nullifying the main query global which you should never do. The give away is your loop (if (have_posts()) : while (have_posts()) : the_post();) and the use of wp_reset_query();. You should be using a proper instance of ...



Top 50 recent answers are included