is posible in wordpress post to replace a single word - wordpress

I have on idea but i dont know if that is posible eg.
I'm writing a post in Wordpress site and I have to write a word too many times, is possible to write it once at the start and in the other part it to be written automatically by a shortcut or do I need a plugin. So if I change that word at the start all the other similar words to be changed automatically, like in word document action find and replace.

Yes, you can use a Shortcode for that. And you can write your own mini-plugin to do it.
The plugin would be simply:
<?php
/**
* Plugin Name: Single Word Shortcode
*/
add_shortcode( 'so', 'shortcode_so_22482571' );
function shortcode_so_22482571( $atts )
{
return "<a href='http://stackoverflow.com'>Stack Overflow</a>";
}
After activation, all [so] occurrences in your posts and pages will be converted to the Stack Overflow link.

You could write a shortcode, like brasoflio said, or you could just do exactly what you were thinking about in Word.... just do a find and replace in your document. Write the document in a text or markdown editor. Replace all instances of {abcdefg} with whatever text you want. Alternatively, you could use a find and replace plugin, or even write your own shortcode. But for something like this, I'd err on the side of laziness. Just write your text in a text editor, find and replace, then copy it in

Related

BuddyPress: Modify Name field template in Register form

The registration form in the Buddypress auto generates html for the dynamic fields (such as name). How can I modify the label text (for example replace "(required)" with an * (asterisk).
If you're looking to make that type of change to BuddyPress profile fields, you can use these filters:
add_filter( 'bp_get_the_profile_field_name', function ($field_name){
if($field_name === 'Name') {
return 'Your Name';
}
return $field_name;
});
add_filter( 'bp_get_the_profile_field_required_label', function($string, $id) {
return '*';
});
If you're looking to make changes to those account fields on the left, it looks like you'll need to use a template file copied from BuddyPress into your theme. A bit more intrusive, but will work.
Copy this: buddypress/bp-templates/bp-legacy/buddypress/members/register.php
To here: /your-theme/buddypress/members/register.php
Hope this helps a bit! Customizing BuddyPress & WordPress markup can get stringy real fast, so I'd recommend tracing the code back to a filter or action if you can find one. If not, look for a template file you can bring into your own theme.
If I did not undestand you wrong, It depends if you want to do it in the client (with Javascript for example) or from the server (with the back-end languaje). But the common languajes have a replace() method that takes two arguments, usually strings with the text you want to replace and the one you want to replace it with.
This page explains the replace method:
https://www.w3schools.com/jsref/jsref_replace.asp
Hope it help

short code are not working on my custom theme

i am not able to use any shortcode in my custom them is there any thing need to add in functions.php to enable shortcode feature??
i have created simple shortcode like in funxtions.php
function custom_shortcode(){
echo "hello there !!!";
}
add_shortcode('mycode', 'custom_shortcode');
but when i am trying to use my short code in post it shows simple [mycode] as display output
i dont know whats wrong in that i think i am missing to add something in functions.php for shortcode feature in my cutom theme
I thing you just need replace "echo" by "return", so:
function custom_shortcode(){
return "hello there !!!";
}
add_shortcode('mycode', 'custom_shortcode');
"Note that the function called by the shortcode should never produce output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode. Producing the output directly will lead to unexpected results. This is similar to the way filter functions should behave, in that they should not produce expected side effects from the call, since you cannot control when and where they are called from."
From: https://codex.wordpress.org/Function_Reference/add_shortcode

How to prevent wordpress authors from inserting html in posts and pages

The wordpress page/post editor enables the authors to insert html in the "html" tab. Some authors may insert ads or other stuff and make the pages cluttersome. I want to disable tags like <script>,<meta>,iframe etc. but want them to insert things like images and embed videos.
Is there a way to do this in wordpress 3.3.1 without removing the "html" tab of the editor ?
You could strip this data when the content is displayed like so
add_filter('the_content', 'clean_post');
function clean_post($data) {
return strip_tags($content, '<p><a><ul><li><img><video>');
}
The string pass into strip_tags as the second parameter is the list of tags you want to allow.
You can also do this before a post is saved. I think the filter is content_save_pre but don't recall off hand. I prefer to save user data as it's entered and clean it up on output.

Possible to add a read more link in an RSS Feed?

This may be a weird or stupid question, but I have the following code (http://pastebin.com/PTFtqkvs) and I want to place a simple "read more" link after the description which links to the the article in the rSS feed - however whatever I do isn't working. Is it even possible to add this option and still conform to the rSS guidelines? This is built using a WP system to show Posts in a certain category.
Any help would be greatly appreciated.
You can hook onto feed specific hooks to add that to your feed content. Something like this in your theme's functions.php would work:
function my_super_awesome_feed_linker( $content ){
$extra = "<a href='" . get_permalink() . "'>Read More...</a>";
return $content . $extra;
}
add_filter( 'the_excerpt_rss', 'my_super_awesome_feed_linker' );
This will add a 'read more' link to all your feeds, though.
In order for this to work, you need to use a normal WordPress loop and the function the_excerpt_rss() instead of what you do in your code, echo $post->post_excerpt;. I've modified your pastebin here:
http://pastebin.com/6Y8pewhW
Also, just a word of advice, this won't really work as a template. WordPress has already sent headers by the time you've gotten to the page's template file. So you'll need to find a way to get those headers sent correctly, or to override them. The two easiest ways would be to filter the header content or to query the posts at 'wp_loaded' before headers are sent.

Wordpress: apply_filters & add_action to the_content = EVIL?

I asked this question over in the actual tutorial, but not sure I'll get an answer anytime soon as it's almost 2 months old... so I'll take a gander here...
Tutorial is here: Build a WordPress Plugin to Add Author Biographies to your Posts
To sum up the tutorial and what the problem is, The tutorial adds an Author Bio on to the end of the content like so (the short version):
function x($content) {
return $content . "Author Bio";
}
add_action('the_content','x');
The Problem:
When someone uses:
$z = apply_filters('the_content', 'some content here');
echo $z;
The Author Bio will end up applied to $z and if $z is echoed out in the middle of some page… the Author Bio would be in the middle of some page… correct? (it's correct because I've tested it...)
Is there a better way to apply something to the end/under/below the_content hook? other than add_action(‘the_content’, ‘some_function’) because this to me seems evil...
or is apply_filters(‘the_content’, ‘some content here’) not the norm or something developers shouldn't be using inside their WordPress templates…? (which seems pretty much the norm, at least upon Google-ing formatting "the_content" outside the loop)...
Using apply_filters('the_content','some content here'), while it may not be 'the norm' (I don't know. I haven't seen it before, but if I needed formatted text, that's what I'd do), is a perfectly valid use of filters to get some text formatted like the content. Unfortunately, there's no better way to append something to content from a plugin. That is just the way these things work.
However, there's a (less than optimal) way of circumventing this. As part of the setup/install process for your plugin, have the user insert a custom function call, action, or filter into their theme. I know several plugins that do this, so it's not all that uncommon. Something like this:
do_action('my_super_awesome_bio_hook');
Would allow you to hook in without worrying about adding a bio to unexpected (and unintended) content. Even better would be inserting a filter:
echo apply_filters('my_super_awesome_bio_filter_hook','');
That would allow your plugin to modify the bio, but also allow the one using the plugin to override it if necessary (like on pages where they're just using excerpts, like search results, etc.).
Hope this helped.
Also, one minor addendum: you should be using add_filter, not add_action to append the Author Bio. add_action still works, but it's a filter you want to be using.
I bumped into a similar issue with a widget I'm dev'ing. I just found this:
http://codex.wordpress.org/Function_Reference/wpautop
Which I'm now going to use instead of add_filters('the_content'). I want the WYSIWYG formatting but I don't want things append to my content because it's not traditional content anymore.

Resources