New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shorttag to show/hide app specific content #211
Comments
We plan to add shorttags to embed alternative content for mobile (notably when it uses Flash). Is that what you have in mind? |
Hi, I was thinking more that if you reuse wordpress pages both in the website and for the app, it would be nice to adjust the output based on where you consume it. My use case now, where a parent site where the site owner had added internal links to sub-pages in the content of the page, but in the app you would rather use the "List subpages option". You could add a special css-class "hide-in-app" and wrap that content with it, and then add a css rule in the apps theme to not display that. But a more user-friendly what would be to have a set over shortcodes to show / hide different part of the page-content. The code code could be somethink like this: <?php
add_shortcode( 'hide_app', 'shorttag_hide_app' );
function shorttag_hide_app( $atts, $content ) {
if ( is_app() ) { // is_app() = some kind of function to check it content is generated for the app
return '';
}
return $content;
}
add_shortcode( 'only_app', 'shorttag_only_app' );
function shorttag_only_app( $atts, $content ) {
if ( is_app() ) {
return $content;
}
return '';
}
?> |
Good point. It could be a nice feature indeed. So I believe the shortcodes would only interpreted when data are retrieved through the WP-AppKit API. @mleroi do you see a way to do the is_app()? |
Yes is_app() is totally doable, we don't have a dedicated function to do that yet but it can totally be integrated to v0.6 for example. I made a quick test with the shortcodes implemented as above and defining is_app() like so:
It works like a charm :) |
Great news :-) It will be integrated in 0.6. |
We may have to consider the following: hide_from_apps and show_only_in_apps will strip content. In other words, a content fragment tagged with hide_from_apps will never reach the app itself. It will be deleted from content before the data are returned to apps. However, sometimes we need to signal that a content was there and can't be displayed in the app. It will allow to style a placeholder saying content unvailable (for example). So I propose to have a notify attribute for the hide_from_apps shortcode with a true|false values or yes|no values. The default value will be false|no (meaning the tagged content is simply stripped and that the app doesn't know about it). If set to true|yes, the content will be replaced by an empty div with a dedicated CSS class (eg. smt-content-not-available). |
Shortcodes created:
I'm wondering if show_only_in_apps could not be named only_in_apps (when making tests I found show_only_in_apps a bit long to write for a shortcode name). But tell me what you think! Any test/feedback on this is welcome! |
@mleroi I've tested shortcodes and they work. However, I think, we should enhance their outputs. To match this new behavior, I would output a Maybe the easiest way is to have a container attribute whose value is the surrounding tag (eg. span, p, div...). If the container attribute is not set, the default value is What do you think of that? |
Defaulting to |
@blupu I've added the container attribute. |
@mleroi what if I don't have a container attribute? |
@blupu if no container attribute then container defaults to |
✨ |
Here's the doc section about those 2 shorcodes "show_only_in_apps" and "hide_from_apps": http://uncategorized-creations.com/wp-appkit/doc/app-content/#2721-shortcodes |
Would a shorttags for showing / hiding content in a post/page be good idea? Probably also to target specific platforms like ios or android?
The text was updated successfully, but these errors were encountered: