How to remove target="_blank" from posts? - wordpress

I'm developing a Wordpress Website. New posts redirect to an external link using
target="_blank"
automatically. And I want it to be deleted from posts. I tried to modify funcitons.php but I still didn't find the appropiate code...
How can I achieve that?

Definitely not the prettiest way, but this should do until you find code that adds target to external links
add_filter('the_excerpt', 'myfilter', 15);
add_filter('the_content', 'myfilter', 15);
function myfilter($content)
{
return preg_replace('#target=["\']?_blank["\']?#mi','',$content);
}

Related

.htaccess remove double https:// http:// in the link

I'm working on one of a client site, some weird reason, a lot of their link show like this: https://http://yourdomain.com/xxxx
It's fine to click the link when I use the console to see the source and will redirect to https://yourdomain.com but when it's front page(without console open), click the button(link), will open https//yourdomain.com, will be missing ":" or "//"
I tried to find where those content come from, but no luck, I can't not use DB to remove that old "HTTP", because everytime they create new resource will still have https://http://
So I wonder can I use a .htaccess file to detect all those "https://http://" links to direct "https://" only.
Thanks for the help!
I don't think it is practical in .htaccess. However, as a temporary solution until you solve the cause of the problem, you should be able to add code to replace bad links at the point WordPress finally "outputs" the page.
I was going to pen a solution but found I only had to modify code for "final output" already here on stackexchange (itself based on this article )
Try adding the following to your theme's functions.php, or for permanence to your own custom site specific plugin.
function my_linkfix_callback($buffer) {
$buffer = str_replace( 'https://http://' , 'https://' ,$buffer);
return $buffer;
}
function my_linkfix_buffer_start() { ob_start("my_linkfix_callback"); }
function my_linkfix_buffer_end() { ob_end_flush(); }
add_action('after_setup_theme', 'my_linkfix_buffer_start');
add_action('shutdown', 'my_linkfix_buffer_end');
Obviously this is just a temporary solution until you solve the cause of the problem

How to replace old external links with new ones in all Wordpress posts automatically?

How to replace old external links with new ones in all Wordpress posts automatically?
The links are in [embed] codes in the posts.
http://old-232.external.link.com/folder/etc.mp4
with
http://newexternallink.com/~newfolder/folder/etc.mp4
Note: the new external link is just an IP address.
Note2: the external links are in some of the posts.
If you take a backup of your database before trying, you may try a search and replace, for example by using a tool plugin like Better Search Replace
I guess there are several other options, but this is one of the plugins which gives you a preview on what is going to change, before doing the actual replacement.
If you add more specific details on what your replacing, you may get more spesific answers as well.
You can do this pretty easy with a simple plugin. Use the WordPress filter the_content
function my_content_filter($content){
//only add text before WordPress posts
if(is_single() && is_main_query()){
//reply all occurances of the old URL with the new URL
$content = str_replace([OLD_LINK], [NEW_LINK],$content);
}
return $content;
}
add_filter( 'the_content', 'my_content_filter' );
For more on this check out my post on how to Add Text Before And After Content In WordPress . Part 5 is about replacing content in all your posts or pages.

wordpress profile builder not redirecting properly after registration

I am using "profile builder pro" plugin of wordpress in wordpress website and it works well except for "redirection after successfull registration" as it is redirecting to the same page.
here is a live link of it
http://www.selfmadesounds.com/dev3/register
Login redirection and register redirection i have set from backend and it is working for login but not for registration.
Any help will be pretty much accepted.
I dont have the pro version but had the same problem, i fixed it by hardcoding the redirect link.
Go to the page "wp-content/plugins/profile-builder/front-end/wppb.register.php"
Move to line 1026 and add the following:
$redirectLink = 'http://www.yourdomain.com/REDIRECT-PAGE';
Just simply overwrite the redirectLink before it go's and redirect.
Hope it helps
Please don't edit plugin files directly! Really bad practice.
You can solve this in a couple of ways, one way is to check if logged in and on a specific page then redirect to another page. There are nicer ways then hardcoding the urls and id, but this is better then editing plugin files directly.
Put this in your functions.php, change url and id to the one you need:
function isLoginPage() {
global $post;
return is_object($post) && (int) $post->ID === 1;
}
add_action('wp', 'redirectFromLoginpage');
function redirectFromLoginpage() {
if (isLoginPage()) {
global $wppb_login;
if (is_user_logged_in() || isset($wppb_login->ID)) { // Already logged in
wp_redirect(site_url() . '/redirect-to-this-url/');
die;
}
}
}

switch wordpress theme base on URL

I have a wordpress website that host several themes inside it.
Now I want to switch the themes for visitor base on the URL that they enter.
for example :
my WP website is at http://www.myblog.com/wp/
but if user enter :
http://www.myblog.com/wp?theme=twentyten -> using twentyten theme
and if user enter :
http://www.myblog.com/wp?theme=mycustomtheme ->using mycustometheme
then
is there any plugins available out there? I've been searching for days but no one seam to work for me.
Any suggestion is very appreciated!
Thanks
I haven't done it, and looking for a minute I don't see a plugin that does that for you. I think your best bet is to make a plugin that would change the theme variable based on the base URL. It's about as simple of a plugin as you can make, so it would be a good one to cut your teeth on if you have any programming ability whatsoever.
This might help:
http://codex.wordpress.org/Theme_Switching
There are 2 plugins noted in that url: http://wordpress.org/extend/plugins/theme-preview/
Theme preview which is what you want.
http://wordpress.org/extend/plugins/theme-switcher/
Theme switcher which do that too and create a sidebar widget so user can change the template.
I've found this good tutorial about base theme swithing on URL.
First, you have to catch the parameter in the URL:
function sjc_add_query_vars($vars)
{
return array('template') + $vars;
}
add_filter('query_vars', 'sjc_add_query_vars');
And then you serve the template:
function sjc_template($template)
{
global $wp;
if ($wp->query_vars['template']=='basic')
{
return dirname( __FILE__ ) . '/single-basic.php';
}
else
{
return $template;
}
}
add_filter('single_template', 'sjc_template');
Please note that the code above check if $wp->query_vars['template']=='basic' and not simply return the template specified in the URL, because it could be a security issue.
for who is still interested you have a WordPress functions that switches the theme
switch_theme( $stylesheet )
see https://codex.wordpress.org/Function_Reference/switch_theme
Just be care to call it in the right time, I would write it in a mu-plugin for use it.

Change management in WordPress

I have a beginner question. What is the best way to address the change management issues in WordPress? I have an all-pages WordPress installation. Suppose name of some event or an entity changes from A to B, then I have to go to all the pages to make that change. Is there any better way of doing it? Like externalization or something.
Or the way similar to how WordPress handle blog name using bloginfo() function. You change blog name at one place and it is reflected everywhere.
Thanks,
Paras
If a URL on your site changes, it is always wise to leave a redirect to the new page. This will help your visitors and search engines. If you create redirects, it doesn't matter too much if you still have a link to the old address in one of your posts. There will probably be a plugin for this, but I don't know which one.
If you really want to keep all links pointing to the latest version, you could replace them with shortcodes that are evaluated to the real URL. <a href="[linkto postid=123]"> would then result in <a href="/2010/08/05/some-post">. I think this is doable, but I don't know whether a plugin already exists for this.
You can also use this technique to replace short snippets, like your company name. The Shortcode API is really easy:
// [company_name]
function replace_company_name($atts) {
return "My Awesome Company";
}
add_shortcode('company_name', 'replace_company_name');
// More generic
// [replace r='company_name']
// [replace r='company_motto']
function do_replacement($atts) {
$replacements = array(
'company_name' => 'My Awesome Company',
'company_motto' => 'A Company so Awesome even you would want to work here!',
);
return $replacements[$atts['r']];
}
add_shortcode('replace', 'do_replacement');
You can hardcode the strings in your plugin code, or you could create a Wordpress options page where users can add and edit new shortcodes.

Resources