Creating a shortcode based on users preferences

Theory It might have been hard to word for you, but is actually quite clear what you are trying to accomplish. A shortcode is a good way to insert dynamic content into a page (or post), the point at which your idea fails is the notion of a “dynamic shortcode”. Use the shortcode to insert … Read more

How to create a shortcode for embedding pdf in iframe?

It depends on how you want the pdfs added but this should probably be a cover all: function embed_pdf_files( $atts, $content = null ){ //add default attributes here. $defaults = array( //’width’ => ‘100%’, //’height’ => ‘1000’ ); //This overwrites defaults with the attributes in shortcode $a = shortcode_atts( $defaults, $atts ); $src = $a[‘src’]; … Read more

Shortcodes Keep Wrapping in

Try https://wordpress.org/plugins/shortcode-empty-paragraph-fix/ It basically removes any p-tags before and after [ or ], before rendering the content. So the output of your shortcodes won’t be wrapped in p-tags

Overriding shortcode $atts for featured products

Alright I want to post this here because of the title of your question. There is a way to change shortcode attributes, but it will also rely on what the developer of the plugin has done. When a plugin is developed with a shortcode there is an option to use the shortcode_atts() function. This happens … Read more

Get shortcode attribute outside of WordPress

Don’t try to parse the shortcodes and then regex the HTML. Use get_shortcode_regex() to parse the raw post content: $content = $content_post->post_content; preg_match_all(“/$pattern/”,$content,$matches); Then crawl $matches to find your shortcode data. Use shortcode_parse_atts($matches[3][0]) (note $matches[3][0] to give the first element within the matched shortcode’s attributes) to pull apart the attribute string. Reference: https://wordpress.stackexchange.com/a/73461/21376

shortcode get thumbnail size

I think your code is very close, try to use wp_get_attachment_image_src() instead: function thumb_medium( $atts, $content = null ) { // return wp_get_attachment_url( get_post_thumbnail_id( $post_id, ‘medium’) ); global $post; $thumb_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘medium’ )[0]; if ($thumb_url) { return $thumb_url; } } add_shortcode(“get_urlthumb”, “thumb_medium”);

Combining similar shortcode functions?

I don’t know exactly what you are trying to do but perhaps something like this: function customfields_shortcode( $atts ) { if (!empty($atts[‘field’]) && get_post_meta( get_the_ID(), $atts[‘field’], true ) ) { $customfield = get_post_meta( get_the_ID(), $atts[‘field’], true ); return “custom field >> $customfield << custom field”; } } add_shortcode( ‘mycustomfields’, ‘customfields_shortcode’ ); echo do_shortcode(‘[mycustomfields field=”customfield_1″]’); One … Read more

Can a shortcode return its own name?

A shortcode can access its own name – it is supplied as third parameter to the shortcode’s callback function, just like that: function test_shortcode_callback( $atts = array(), $content = null, $tag ) { return $tag; } add_shortcode( ‘test_shortcode’, ‘test_shortcode_callback’ ); // So running this shortcode [test_shortcode] // Will return this test_shortcode

Replace / Remove Shortcode after 1st run / post

You don’t need a shortcode in a traditional sense. You could use something like {imageurl=””http://google.de/aImage.jpg} You would use the filter content_save_pre to run before the content is saved to the database a search and replace with the img markup which you get from media_sideload_image(). media_sideload_image() downloads the image from a URL adds it to the … Read more

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