how to write short code in word press

According to the WordPress documentation, “a minimal example of the PHP code required to create shortcode with attributes” is // [bartag foo=”foo-value”] function bartag_func( $atts ) { extract( shortcode_atts( array( ‘foo’ => ‘something’, ‘bar’ => ‘something else’, ), $atts ) ); return “foo = {$foo}”; } add_shortcode( ‘bartag’, ‘bartag_func’ ); You can find more detailed … Read more

Substituting value via shortcode

If you put variables inside a string, you have to use ” double quotes. So: // This: $qstr=” SELECT * … ORDER BY $wpdb->posts.post_date DESC “; // becomes… $qstr = ” SELECT * … ORDER BY $wpdb->posts.post_date DESC “;

Execute Shortcodes when submitting post

That’s not how shortcodes work. Shortcodes are meant to be interpreted whenever the page is rendered – they’re used when WordPress filters the page/post content. What you’re looking for is a content template. A tag the user can add to the page that will be converted into something else when the post is saved, like … Read more

get_posts not working on homepage?

The get_posts() argument is supposed to be numberposts not posts_per_page and you were passing it as string. Try making it an integer. function listposts( $atts ) { $atts = shortcode_atts( array( ‘tag’ => ‘jan-2011’, ‘numberposts’ => -1, ‘orderby’ => ‘post_date’, ‘order’ => ‘asc’, ‘post_status’ => ‘any’ ), $atts ); $catposts = get_posts( $atts ); $out=””; … Read more

How to execute a shortcode?

Well, as Christopher Davis mentioned – do_shortcode works fine with extra stuff included, so I decided to reset my server and echo do_shortcode(get_option(‘my_option’)); started to work perfectly. So I guess the answer has always been here, execute shortcodes with do_shortcode.

How to deal with WordPress bug: can’t use wrapped and unwrapped shortcode on same post

According to a new post by mdawaffe on the trac ticket referenced in this question: [test id=”1″/] first self closed, now [test id=”2″]with content[/test] [foo attr/]bar[foo attr/]bar[/foo] [test/] [test]foobar[/test] [test id=”1″][/test] All these cases now work. Apart from unit tests, this ticket can be closed. I am assuming this means it will not be an … Read more

how to create a fav icon shortcode?

OK… as it sometimes goes i cant rest until i find a way and i found a way to get the fave icon to proeprly display using google 🙂 its really simple: // here i get my URL from my custom post type $directoryNoHttpUrl = get_post_meta( $post->ID, ‘directory_url’, true ); //here i clean the url … Read more

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