Tag Info

New answers tagged

0

From the sizes you have added (and the image_size_names_choose filter), your use should be able to upload an image via the media library and then choose the proper image size when putting the image into their content with the media button. When they are in the media library viewer, they should be able to click an image and then look at the lower right area ...


0

The images URL are direct. They are not part of WP rewrite system, they are not stored as explicit metadata, they are never used for reverse lookups in core. It is possible to make fair attempt at reversing URL, see Turn a URL into an Attachment / Post ID. But it's not a normal workflow or reliable. You could as well have users put attachment IDs in ...


0

OK so I figured it out, I'm sure they're much more elegant ways of doing this but it works for what I needed to do. <?php // Single Audio & Playlist player global $post; $args = array( 'post_parent' => $post->post_parent, 'numberposts' => -1, 'post_status' => 'null', ...


2

Some ideas for your attachments file: A simplification: $tmp = $post; // Store the current global post object $post = get_post( $post->post_parent ); // Use the post parent post object $media = get_attached_media( 'audio' ); if( $media ) { $sc = "[audio]"; if( count( $media ) > 1 ) { $ids = join( ',', ...


2

Your problem is in this section foreach( $voc_pages as $voc_page ) { $voc_link = '<a href="'.get_page_link( $voc_page->ID ).'">'.$voc_page->post_title.'</a>'; return $voc_link; } You return $voc_link after just the first iteration, stopping the function and returning its value. You should take return $voc_link; outside your ...


0

I know this is a dead horse and that Chip has pretty much covered it, but wanted to add a few thoughts. If you make a living programming and find yourself working on wordpress sites under deadlines, you are going to find that it really comes down to time. More often than not, especially for those just starting out, it is much faster and simpler to just add ...


1

You can use the pre_post_update filter hook to achieve this. Unfortunately the Codex isn't very good for this hook, but it's a simple enough one to understand and can be found in wp-includes/post.php on line 3335 (WP 4.1). add_filter( 'pre_post_update', 'my_replace_shortcode', 2, 99 ); function my_replace_shortcode( $post_id, $data ){ ...


1

You could try mashing all the patterns together in one big regexp or and then doing a simple line by line parse of the content: function theme_oembed_videos() { global $post; if ( $post && $post->post_content ) { global $shortcode_tags; // Make a copy of global shortcode tags - we'll temporarily overwrite it. ...


0

Due a bug in get_tag_regex(), this won't work properly. See bug #26674. You can use the get_media_embedded_in_content() function for both shortcode and embedded media (it looks for these HTML tags: audio, video, object, embed, or iframe), just be sure to use content with applied filters and shortcode executed. For example: $post_id = 125; $post = ...


3

Try this. Add the code below to your functions.php file - add_shortcode('cat_description', 'my_cat_description_shortcode'); function my_cat_description_shortcode($atts){ $a = shortcode_atts( array( 'id' => 0, ), $atts ); return category_description($a['id']); } Should you wish to call the shortcode from a template (unnecessary ...


0

If you want to insert a shortcode directly into the php template, you have to use do_shortcode(). For example: <?php echo do_shortcode( '[the_shortcode id="4"]' ); ?>


0

Here is the solution I come up with after 30 minutes researching: function wpse_175564() { // The html goodies with shortcodes $htmlcodes = '<div class="akismet_activate"> <div class="aa_a">A</div> <div onclick="document.akismet_activate.submit();" class="aa_button_container"> ...


0

In principle PHP can do this with exec(), so WordPress can as well. You do not specify enough details, but it sounds either like form submit or Ajax request. Different implementation but in the end you will be running exec() just as well. PS think really hard on how secure it will be and which kind of data you will allow to pass this way.


0

Try this function out, be sure to add your shortcode in the array // (OPT) STOP SHORTCODES THAT DON'T USE INLINE CONTENT FROM BEING WRAPPED IN A P TAG (until WP fixes this) // ** NOTE -> BE SURE TO change the array to the shortcodes you are using! add_filter('the_content', 'the_content_filter'); function the_content_filter($content) { // array of ...


0

This is a filter in WordPress called wpautop it is there to make formatting cleaner when publising posts, however when you want more control over formatting it can be a pain. It basically wraps returns in paragraphs so that the space you see in the editor is obeyed on the front end. You can disable it completely by placing this in your functions.php ...


2

I believe the real issue you had was with echoing your data instead of returning it. A shortcode should return the output to be drawn, which is then drawn in place of the short code. Here is the code using HEREDOC syntax for outputs and the query. I believe this makes things much more readable once you get used to it. See ...


-1

function homepage_featuredproducts( $atts , $content = null ) { if( empty( $content ) ) $content='no content to display'; return $content; } add_shortcode( 'homepage_featuredproducts', 'homepage_featuredproducts' );


0

Have you tried: function my_members_only_shortcode($atts, $content = null) { if ( !is_user_logged_in() ) { $content = '<p>This content is for members only. Please log in or register first.</p>' . do_shortcode('[do_widget "Social Login" ]'); } return $content; } That should replace the content with your message and special ...


0

I figured it out. For anyone who needs to find this solution I edited the above code. I changed: 'order' => 'DESC' to 'order' => 'ASC' , and 'orderby' => 'meta_value_num' to 'orderby' => 'meta_value' to achieve the order I wanted.


0

From my understanding of shortcodes, you would need to create a shortcode for each pixel. It would be much easier to define a single shortcode, then use attributes to define a font-size. function font_callback( $attributes, $content = null ) { extract( shortcode_atts( array( 'size' => '12px' ), $attributes ) ); return '<span ...


0

depend on your code if you use it as gallery shortcode i think this will work : <div class="gallery-content"> <?php if( has_shortcode( $post->post_content, 'gallery' ) ) : if ($ids != '') { $images = explode(',', $ids); } else { $images = get_children(array('post_parent' => get_the_ID(),'post_type' => ...


1

An alternative you have not mentioned is to customize the shortcode experience, since shortcodes are a UX failure for the end user. Create a specific shortcode button on the editor so the user can select text and click an actual button. You can go further and attach some code to error check what the user selects or ask if the selected text is correct. ...


0

How about simply using the get_post_gallery() function. This is exactly the way, most themes are checking if a post has a gallery to print the correct body CSS classes: if ( get_post_gallery() ) { // run your code in here } P.S. I really don't like solutions that search the whole content for anything, even if string functions are typically quite fast ...


2

You can try the image_send_to_editor filter: /** * Wrap the inserted image html with <figure> * if the theme supports html5 and the current image has no caption: */ add_filter( 'image_send_to_editor', function( $html, $id, $caption, $title, $align, $url, $size, $alt ) { if( current_theme_supports( 'html5' ) && ! ...


0

The problem seems to be in the Loop. Inside the Loop you are not incrementing the $the_query. You may change the code for the Loop as below: // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); // Add this line to fix the issue smr_product_the_frontend_item(); } } else { ...


0

It was solved by a coworker. function removebreaks($content) { $content = str_replace('<br>', '', $content); $content = str_replace('<br/>', '', $content); $content = str_replace('<br />', '', $content); $content = str_replace('<BR>', '', $content); $content = str_replace('<BR/>', '', $content); ...


0

Theme I had did thinks like (don't know what's the problem here yet): <?php $page_content = get_post(); ?> <h2> <?php echo $page_content->post_title;?> </h2> <div> <?php echo $page_content->post_content;?> </div> echo the_content() didn't do anything. I had to replace a line with <?php echo ...


1

This might help. On the YouTube video page, choose Share, then choose Embed, then choose Show More. Remove checks in boxes for "Show Player controls" and "Show Video Title and Player Actions." Choose largest given width size or custom size that is equal to or slightly greater than your div container width. Copy the code. Paste the code into your post, ...


5

I am not sure why your query is returning more IDs than necessary. The $args for get_users look correct. By default get_users does not support orderby=rand, but you can overwrite that option. See below: function random_user_query( &$query ) { $query->query_orderby = "ORDER BY RAND()"; } // Usage: [random_users how_many = 3] add_shortcode( ...


1

No, there is no core shortcode for this. The site name is available as an option, in facts get_option('blogname') returns the blog name. Moreover, get_bloginfo('name') / bloginfo('name') can be used to get / echo the site name. Of course, you can't use that functions as a shortcode by default, so if you want to obtain that, and you don't want to edit ...


0

Altough is not clear whether you have the willing or not to dig inside the code, a plugin will allow you to use PHP inside a post/page right from the admin panel. This one seems to be ok for you : https://wordpress.org/plugins/php-code-for-posts/ Note: I am not involved in this plugin development. Thanks to it, you might be able to use any WordPress ...


0

I donĀ“t think that is possible without altering the functions.php or some kind of plugin. You have to pass the "barrier" between PHP in the background and HTML, CSS etc. in the foreground and that is either done by the functions.php or a plugin.


1

Shortcode callbacks get a third argument with the shortcode name. there's a note about this in the docs: Appears to always appear as third argument as of 2.9.2. add_shortcode('foo', 'wpse173855_shortcode'); add_shortcode('bar', 'wpse173855_shortcode'); function wpse173855_shortcode($atts, $content, $name) { echo '<pre>'; var_dump($name); ...


1

I think you just forgot to run the shortcodes [foo a='b'] and [bar a='c'] through the do_shortcode filter: do_shortcode( '[foo a='b'] [bar a='c']' ) The output of the_content() is filtered through the do_shortcode, so you can just add it into your editor instead. Running your code I get the following output for the $arguments dump: array (size=1) 'a' ...


2

QUESTION AND ANSWER REVISITED There are sometimes these questions that nags you and hunts you down later in life again, and this is one such question. This question had me thinking about an alternative solution to the problem. As I already stated, custom fields and meta boxes are there to store small pieces of meta data, and not to act as an extension to ...


1

You can use "rilwis/meta-box " for this . For dynamic slider use this snippet, <?php $images = rwmb_meta( 'gallery', 'type=image' ); foreach ( $images as $image ) { echo "<a href='{$image['']}' title='{$image['title']}' rel='thickbox'><img src='{$image['full_url']}' alt='{$image['alt']}' /></a>"; } ...



Top 50 recent answers are included