admin管理员组

文章数量:1406937

I added shortcodes to the theme I'm using, but when I try to use them in a page, it gives me a blank page. I have seen a solution to this problem saying to use remove_filter("the_content", "wpautop"); but I'm not sure that this will work. If it will, please let me know, and please let me know where to put that code. Otherwise, what can I do to fix this issue. If you need to see what shortcodes I'm trying to add, let me know and I'll post a file with them. Thanks in advance.

EDIT Here are the functions I am using to add the shortcodes:

function facebook($atts) {
    extract(shortcode_atts(array(
        "source_url" => '/'
    ), $atts));

    $url = ".php?method=links.getStats&urls=".urlencode($source_url);
    $xml = file_get_contents($url);
    $xml = simplexml_load_string($xml);
    $likes =  $xml->link_stat->like_count;

    return '<div class="column"><a href="' . $source_url . '"><i class="fa fa-facebook" style="color: white; border: 1px solid white; border-radius: 100%; font-size: 28px; height: 38px; line-height: 40px; margin: 5px; text-align: center; width: 38px;" aria-hidden="true"></i><span style="font-size: 150%;">' . $likes . ' likes</span></a></div>';
}
add_shortcode("facebook", "facebook");

function twitter($atts) {
    extract(shortcode_atts(array(
        "user_id" => 'team569A',
        "link" => ''
    ), $atts));

    $xml = new SimpleXMLElement(urlencode(strip_tags('/'.$user_id.'.xml')), null, true);
    return '<div class="column"><a href="' . $link . '"><i class="fa fa-twitter" style="color: white; border: 1px solid white; border-radius: 100%; font-size: 28px; height: 38px; line-height: 40px; margin: 5px; text-align: center; width: 38px;" aria-hidden="true"></i><span style="font-size: 150%;">' . $xml->followers_count . ' followers</span></a></div>';
}
add_shortcode("twitter", "twitter");

function instagram($atts) {
    extract(shortcode_atts(array(
        "username" => '569A_',
        "link" => ''
    ), $atts));

    $raw = file_get_contents('/'.$username);
    preg_match('/\"followed_by\"\:\s?\{\"count\"\:\s?([0-9]+)/',$raw,$m);

    return '<div class="column"><a href="' . $link . '"><i class="fa fa-instagram" style="color: white; border: 1px solid white; border-radius: 100%; font-size: 28px; height: 38px; line-height: 40px; margin: 5px; text-align: center; width: 38px;" aria-hidden="true"></i><span style="font-size: 150%;">' . intval($m[1]) . ' followers</span></a></div>';
}
add_shortcode("instagram", "instagram");

function discord($atts) {
    extract(shortcode_atts(array(
        "server_code" => '365923825860214784',
        "link" => ''
    ), $atts));

    $JsonIn = file_get_contents('/'.$server_code.'/embed.json');
    $JSON = json_decode($jsonIn, true);

    $membersCount = count($JSON['members']);

    return '<div class="column"><a href="'.$link.'"><i class="fa fa-687474703a2f2f692e696d6775722e636f6d2f65597779386c" style="color: white; border: 1px solid white; border-radius: 100%; font-size: 28px; height: 38px; line-height: 40px; margin: 5px; text-align: center; width: 38px;" aria-hidden="true"></i><span style="font-size: 150%;">'. $membersCount . ' members</span></a></div>';
}
add_shortcode("discord", "discord");

I don't currently have access to the error.log file. I will note though that not the entire page is blank. The theme still shows up, along with page title, but not the content of the page.

EDIT 2 I just went to look for the error.log file, but there does not seem to be one. I have no clue what to do from here.

I added shortcodes to the theme I'm using, but when I try to use them in a page, it gives me a blank page. I have seen a solution to this problem saying to use remove_filter("the_content", "wpautop"); but I'm not sure that this will work. If it will, please let me know, and please let me know where to put that code. Otherwise, what can I do to fix this issue. If you need to see what shortcodes I'm trying to add, let me know and I'll post a file with them. Thanks in advance.

EDIT Here are the functions I am using to add the shortcodes:

function facebook($atts) {
    extract(shortcode_atts(array(
        "source_url" => 'https://www.facebook/the569a/'
    ), $atts));

    $url = "http://api.facebook/restserver.php?method=links.getStats&urls=".urlencode($source_url);
    $xml = file_get_contents($url);
    $xml = simplexml_load_string($xml);
    $likes =  $xml->link_stat->like_count;

    return '<div class="column"><a href="' . $source_url . '"><i class="fa fa-facebook" style="color: white; border: 1px solid white; border-radius: 100%; font-size: 28px; height: 38px; line-height: 40px; margin: 5px; text-align: center; width: 38px;" aria-hidden="true"></i><span style="font-size: 150%;">' . $likes . ' likes</span></a></div>';
}
add_shortcode("facebook", "facebook");

function twitter($atts) {
    extract(shortcode_atts(array(
        "user_id" => 'team569A',
        "link" => 'http://www.twitter'
    ), $atts));

    $xml = new SimpleXMLElement(urlencode(strip_tags('https://twitter/users/'.$user_id.'.xml')), null, true);
    return '<div class="column"><a href="' . $link . '"><i class="fa fa-twitter" style="color: white; border: 1px solid white; border-radius: 100%; font-size: 28px; height: 38px; line-height: 40px; margin: 5px; text-align: center; width: 38px;" aria-hidden="true"></i><span style="font-size: 150%;">' . $xml->followers_count . ' followers</span></a></div>';
}
add_shortcode("twitter", "twitter");

function instagram($atts) {
    extract(shortcode_atts(array(
        "username" => '569A_',
        "link" => 'http://www.instagram'
    ), $atts));

    $raw = file_get_contents('https://www.instagram/'.$username);
    preg_match('/\"followed_by\"\:\s?\{\"count\"\:\s?([0-9]+)/',$raw,$m);

    return '<div class="column"><a href="' . $link . '"><i class="fa fa-instagram" style="color: white; border: 1px solid white; border-radius: 100%; font-size: 28px; height: 38px; line-height: 40px; margin: 5px; text-align: center; width: 38px;" aria-hidden="true"></i><span style="font-size: 150%;">' . intval($m[1]) . ' followers</span></a></div>';
}
add_shortcode("instagram", "instagram");

function discord($atts) {
    extract(shortcode_atts(array(
        "server_code" => '365923825860214784',
        "link" => 'https://discordapp/invite/FjuqqFc'
    ), $atts));

    $JsonIn = file_get_contents('https://discordapp/api/guilds/'.$server_code.'/embed.json');
    $JSON = json_decode($jsonIn, true);

    $membersCount = count($JSON['members']);

    return '<div class="column"><a href="'.$link.'"><i class="fa fa-687474703a2f2f692e696d6775722e636f6d2f65597779386c" style="color: white; border: 1px solid white; border-radius: 100%; font-size: 28px; height: 38px; line-height: 40px; margin: 5px; text-align: center; width: 38px;" aria-hidden="true"></i><span style="font-size: 150%;">'. $membersCount . ' members</span></a></div>';
}
add_shortcode("discord", "discord");

I don't currently have access to the error.log file. I will note though that not the entire page is blank. The theme still shows up, along with page title, but not the content of the page.

EDIT 2 I just went to look for the error.log file, but there does not seem to be one. I have no clue what to do from here.

Share Improve this question edited Oct 9, 2017 at 15:40 MattChris asked Oct 9, 2017 at 1:57 MattChrisMattChris 1215 bronze badges 7
  • wpautop isn't going to result in a blank page. You likely have a coding error. Can you post the code for the shortcodes. – Jacob Peattie Commented Oct 9, 2017 at 2:03
  • Are they all giving you trouble or is it only one shortcode that's causing your blank page? Also, as a best practice, your functions should all have some kind of prefix on them that makes them unique so that you don't run into colliding function names. That means function facebook($atts) { should be function koalaking_facebook($atts) { or something like that, and add_shortcode("facebook", "facebook"); should be add_shortcode("facebook", "koalaking_facebook"); – socki03 Commented Oct 9, 2017 at 14:41
  • @socki03 - All of them are giving me trouble. I went and updated the function names so they are all distinguished, but it is still causing issues. – MattChris Commented Oct 9, 2017 at 15:26
  • The only thing I noticed just now is that in the discord function, 2 variables have different capitalization $JsonIn and $jsonIn. Might not fix it, but it's a start. Try changing the line to $JSON = json_decode($JsonIn, true); – socki03 Commented Oct 9, 2017 at 15:32
  • @socki03 - I made the edit to that line, but still nothing. – MattChris Commented Oct 9, 2017 at 15:42
 |  Show 2 more comments

2 Answers 2

Reset to default 1

I agree that there is a coding error - a blank WP page is almost always caused by a fatal PHP error.

You should look at the error.log file in your site's root folder. That will tell you what/where about the error.

If you edit your question to include the error messages found in error.log, that will help. As will the code you are using to create/use the shortcode.

I figured out the issue; socki03 was right. I had old code that was no longer functional for my twitter shortcode. I did some more digging and found new code that works as expected, so now the website works perfectly. Here is the code for anyone who wants it:

function twitter_followers($atts) {
    extract(shortcode_atts(array(
        "user_id" => 'team569A',
        "link" => 'http://www.twitter'
    ), $atts));

    $JSON = json_decode(file_get_contents('https://cdn.syndication.twimg/widgets/followbutton/info.json?screen_names='.$user_id), true);
    $follower_count = $JSON[0]['followers_count'];

    return '<div class="column"><a href="' . $link . '"><i class="fa fa-twitter" style="color: white; border: 1px solid white; border-radius: 100%; font-size: 28px; height: 38px; line-height: 40px; margin: 5px; text-align: center; width: 38px;" aria-hidden="true"></i><span style="font-size: 150%;">' . $follower_count . ' followers</span></a></div>';
}
add_shortcode("twitter", "twitter_followers");

本文标签: Shortcode produces blank page