I'm building a plugin which will pull custom meta post automatically.
For example if I have a post with content
"A post content"
when display content in the theme used the_content() tag, I want to display as :
A post content <br> <div id="custom-data">Some custom data</div>
In that way, I can build a plugin to pull custom meta post automatically and re-style the custom data.
Anyone know it? Thanks!
You can use add_filter() to add text to the content. Here's an example:
function functionname($text){
$text .= 'Some extra text, added below the content';
return $text;
}
add_filter('the_content', 'functionname');
There are many filters you can hook on, here's a list: http://codex.wordpress.org/Plugin_API/Filter_Reference
Related
I'm using shortcodes in my Wordpress page to display a responsive Google Map centered at specific location. To do it I'm using shortcode supported by external Wordpress plugin. Such shortcode is let's say [map address="New York"].
As all my Wordpress posts titles are names of the cities, I would like to automatize the process and be able to display the titles of the post in place of the address parameter in [map] shortcode.
Is it possible? Is there any way to do it? As far as I know nesting code or variables in shortcode isn't supported by Wordpress but maybe there is some kind of a workaround.
The same behavior I'd like to accomplish for 'custom field' - really similar situation.
I'd appreciate any help and any advice
Try to put this code to functions.php file in your theme:
function mymap_shortcode() {
echo do_shortcode('[map address="'.esc_html( get_the_title() ).'"]');
}
function mymap_shortcodes_init() {
add_shortcode('mymap', 'mymap_shortcode');
}
add_action('init', 'mymap_shortcodes_init');
And then in posts/pages (or even put it directly to template, or create another filter to add that) use shortcode [mymap] that will run [map] shortcode with current page title as parameter.
I have a custom text widget but I cant write html code in it.
Is there any way to add html support to custom widget?
Note: I know there is Wordpress Text Widget but I have to use this custom widget.
Here is my code: https://codepaste.net/ct4yee
Thanks for help!
Your script is calling strip_tags() which removes HTML tags. See http://php.net/manual/en/function.strip-tags.php.
I have a shortcode [table id=table /]
I want to do something like this <?php echo do_shortcode('[table id="'.$post->post_name.'"/]'); ?>
I want the slug to appear as the table id.
What am I doing wrong?
Given that you mentioned in the comments that you're trying to use this shortcode in a widget - widgets don't parse shortcodes by default.
To make most widgets parse shortcodes (most being those with text fields that apply the widget_text filter), you can add the following to your theme's functions.php:
add_filter("widget_text", "do_shortcode");
You can then refer to this shortcode directly in your widget text like you would expect you can:
[table id=... /]
EDIT:
If you have any trouble running shortcodes that are on their own line, it may be because they get wrapped in <p></p> tags automatically by Wordpress. To stop this happening, add this filter before the one added above:
add_filter("widget_text", "shortcode_unautop");
The shortcode_unautop() function simply stops shortcodes from being wrapped in paragraph tags like is Wordpress' default behaviour in most text fields.
I am making a custom theme with shortcodes. The theme is ready, but now I need to make the shortcodes.
The problem is that the shortcodes don't work in my posts, they are only visible on my pages. When I add a shortcode in my post, the post displays nothing.
Here is the shortcode code:
function rss_subscribe_link() {
return 'Enjoy what you\'re reading? Subscribe to our RSS feed here now.'; }
add_shortcode('rss-subscribe', 'rss_subscribe_link');
add_filter('widget_text', 'do_shortcode');
Does anyone know how to solve this problem?
Greets,
Joren
This could happen if your post content is displayed via get_the_content() which is a function that returns the content without applying the default filters (wpautop, do_shortcode etc) that are applied normally when you use the_content(). Could you confirm if this is the case?
I am not a pro in wordpress hooks and filters and therefore anyone expert can help me in creating a filter for a facebook wordpress plugin so that it shows the comments title on site.
the plugin url is
http://wordpress.org/support/plugin/facebook
and here is the documentation about how to get this solved...
facebook_wp_comments_title
The Facebook plugin for WordPress implementation of the Comments Box social plugin overrides your WordPress theme's comments template including the displayed title of the comments section. Act on the string value passed to this filter to affect the inner text of h2.comments-title inside the custom comments template.
You would use the facebook_wp_comments_title filter like this:
function my_custom_filter( $title ) {
$title = 'Your title goes here';
return $title;
}
add_filter( 'facebook_wp_comments_title', 'my_custom_filter' );
Ref: http://codex.wordpress.org/Function_Reference/add_filter