WordPress ShortTag Custom Variable - wordpress

I like to have a whole website build in wordpress. All through the site there will be telephone number, address, some link here and there...
I like to be able to defin variable shorttag in the admin panel somewhere, and be able to insert it in the WYSIWYG like that :
you can contact us anytime [phone] or visit us here : [address]
so changing addres or number is a snap !
any idea, i got http://wordpress.org/extend/plugins/custom-configs/screenshots/ but need to insert in php not shorttag...

You can use the do_shortcode() function to output the shortcode values using php. Assuming that
Example:
<? echo do_shortcode('[phone]'); ?>
Using your plugin is easy to define shortcodes that are outputting the content of a custom setting
function get_phone($atts, $content = null) {
return get_config('phone-settings');
}
add_shortcode('phone', 'get_phone');
Assuming that in your plugins, you have defined a custom settings with the key phone-settings

Related

Plugin Development: Dynamically change post title (the_title()) from a plugin, without changing database title

I am developing a custom plugin that needs to change the post title dynamically (NOT the "title" tag for the head) without using a page template.
I want the end user of the plugin to be able to use their own theme templates, which will already output the title, usually in an h1 tag, but I don't know where and how for sure, because it is not my theme.
I will need to just change the output on the frontend, not in the database. I want to change it based on whether a url's query string matches certain values, or whether the frontend user is logged in or not. I know how to do this from a custom template, but I want to do this from a template the user already has selected.
I noticed that if I filter the_title(), it changes it everywhere in the admin dashboard and in the frontend navigation menus, which is what I don't want, I just want to change where it is outputted in the user's page template (usually in an h1 tag).... does anyone have any suggestions on how to go about this?
You can use the_title filter, which would have influence only on front-end, this doesn't change record in Database. Your code would be something like this:
add_filter( 'the_title', 'add_text_to_post_title' );
function add_text_to_page_title( $title ) {
if( is_post() )
$title = 'Your text: '. $title;
return $title;
}

Wordpress: Polylang and ACF Options page on ajax calls takes default language value

I'm working on a website, which is multilingual.
We're using Polylang and the ACF custom fields plugin.
Works fine in general, the issue is with the ACF Option pages.
The option pages are translated also in different languages.
The content we are taking from there is being displayed according to translation - in english on the english version of a page, french on the french etc.
The problem: We have a contact us form, where we take the recipients email address from the ACF option pages.
(We want to send it to a different recepient when its a different language.)
Here it always takes the email address from the default language option page and I don't understand why.
We are taking the email recipient for the ajax call with get field command, like on pages displaying content:
get_field('service_email', 'option' );
Anyone got an idea what could cause this? Or where to look?
In the end we found the solution. It took a bit of digging, but I hope this helps if anyone encounters the same issue.
We needed to add the following setup in the functions.php of our theme to have the ACF options pages also translated for the each language:
// Translating Options Page Compatibility
// add filter with the path to your acf installation
add_filter('acf/settings/default_language', 'my_settings_default_language');
add_filter('acf/settings/current_language', 'my_settings_current_language');
function my_settings_default_language( $lang ) {
if($lang == "") {
$lang = pll_default_language(); // pll_ is a polylang function
}
return $lang;
}
function jfrog_settings_current_language( $lang ) {
$lang = pll_current_language();
return $lang;
}
Side Note: We're using a theme installed version of ACF.
hope this helps, Cheers

advanced-custom-fields the_field function not work in wordpress

I'm trying to use the the_field(); function in wordpress but did't work
also I tried to use the get_field(); function and same problem what I can do
<?php the_field('contact_form_short_code'); ?>
I am using advanced-custom-fields plugin the free version
the_field('contact_form_short_code') will try to get the field info from the current post in the loop. If you're not currently in a loop it will look to the current page/post.
If you want to reference a post from outside the loop you must specify the post ID, eg: the_field('contact_form_short_code', $post_id)
Hope that helps
Check if your field group location points to your template, taxonomy or custom post type, after that try to use echo to call your field.
Check this link www.advancedcustomfields.com
If you want to display the shortcode (contact_form_short_code) specified in the admin panel via a custom field (ACF), you need to use the do_shortcode(); function.
In your case, the code looks like this:
<?php
//In the admin panel we fill the shortcode of the contact form, for example CF7.
//[contact-form-7 id="1" title="Form"]
$cform = get_field('contact_form_short_code', $post_id);
//Output of shortcode
echo do_shortcode($cform);?>

Create a Dynamic Site Address in a Wordpress Menu

I'm doing some work on an existing site that is based on the Wordpress theme, but uses about 15 plugins (Including Buddypress). One in particular is the WP Sliding Login|Dashboard plugin, which has a link to the user's activity feed. I found the code that creates that link in the wp-sliding-login-dashboard.php file:
<?php
if ( is_user_logged_in() ) {
global $current_user;
$username = $current_user->user_login;
echo ' <li>Activity Feed</li>';
}
?>
I want to use this code to send the user to the same location, but using the a link at the top of the home page. Unfortunately, the home page links are all created using Wordpress menus, which as far as I can tell, only allow for the use of static links attached to existing pages.
Do I create a dummy page to link to that exits only to execute the above code? Is that even possible? Picture a five-year-old trying to read Shakespeare, and you have an idea of my ability as a coder, so feel free to engage me as such - i.e. if you say, "oh just create a scoping function instead of creating a global function", i would stare at you drooling and confused.
Images for clarity: The sliding login menu (WP-Sliding Login|Dashboard Plugin), showing the target URL in the status bar as www.ferrignofit.com/members/FerrignoFit/activity/ (the current logged in user is FerrignoFit):
http://i.imgur.com/NPvmCXU.jpg
The main page Wordpress-based menu, which i want to go to the above URL, but is currently going to www.ferrignofit.com/activity/, a different page:
http://i.imgur.com/dIiFpDC.jpg
So here's a jQuery solution for this specific issue. From seeing the images you have, what you want to do is target a specific anchor in your dynamic WordPress menu.
As you may be aware, you can create custom links for the WordPress menu function... it simply lets you set a label and a URL. You should create such item and just give it a hash for the URL for now.
Now set a class for that specific menu item so you can have a nice handle for jQuery to target it (otherwise you can use the dynamic class that WordPress creates for each specific menu-item).
One you have a class set or you know what you need to target then you can add this block of code before your menu.
<?php if (is_user_logged_in()){ ?>
<script>
$(document).ready(function(e) {
var targetNav = $('li.customClassName a');
var userName = '<?php $current_user = wp_get_current_user(); echo $current_user->display_name;?>';
var userUrl = 'http://www.mywebsitename.com/members/'+ userName +'/activity/';
targetNav.attr('href',userUrl);
});
</script>
<?php } else { ?>
<script>
$(document).ready(function(e) {
var targetNav = $('li.customClassName a');
targetNav.attr('href','http://www.stackoverflow.com');
});
</script>
<?php } ?>
Please not that I am using PHP to get the current username in WordPress, after I get the username and I store it in the userName variable I use it in the userUrl to set it with the path that I want.
On another note, I'm using is_user_logged_in() so you have the option of making the link something else if the user is in fact not logged in. So with this if statement one of the two blocks of code will be output by PHP.
As soon as my two variables are set, I simply target my menu item with jQuery and modify the href attribute to replace the hash with the path and dynamic username.
Though this is not very good practice to mix JS and PHP, I'd like to learn myself here what other solutions someone can suggest so I'm posting this as a solution for your very specific issue.
I tested this code with my own WordPress site and it works, just remember that this code NEEDS to be in a PHP file otherwise the PHP used in the <script> tags won't mean anything to the server if it's in a .js file.

How to create a profile page in Wordpress Multisite

I can't find a way to create a front-end profile page for all users under Wordpress Multisite Network. I also wanted the profile page to be on the main site and not on sub-sites if possible. I don't want to use any social network plugins like buddypress.. I just want to create a page like http://mainsite.com/profile/username
Is there a way to accomplish this?
Maybe you might check out Buddypress which is a social layer on top of Wordpress and is able to do what you need (i.e. something like http://mainsite.com/profile/username).
Link: http://buddypress.org/
More specifically, in Buddypress the default behaviour is http://mainsite.com/members/username
I have noticed that you have edited the question and that you are looking for a way to accomplish this without any plugin. There are a series of tags in Wordpress to show the author's data. So basically you could create a page and then use the_author_meta tags. For example the following code echoes the first and last name of a user whose name is stored in $userID:
<?php
$pagename = $userID;
echo the_author_meta(user_firstname, $userID );
echo the_author_meta(user_lastname, $userID );
?>
Please note that the variable $pagename is empty in case you use a static page as home page, but it is not your case.
Source: https://codex.wordpress.org/Template_Tags/the_author_meta

Resources