programmierfrage.com
Ask a question    Sign Up Sign In
  • Train typing speed
  • About/Contact
  • Privacy Policy
  1. Home
  2. php - Wordpress custom sidebar on single page

94 votes
1 answers

php - Wordpress custom sidebar on single page

Get the solution ↓↓↓

I'm trying to display a custom sidebar in a page. The code works with custom post types "news" posts but wont work with the page "na-midia". In the page the defaul sidebar is shown.

// Custom Sidebar
function prefix_custom_sidebar() {

    register_sidebar( array(
        'name'          => __( 'Custom Sidebar MГ­dia', 'page-builder-framework' ),
        'id'            => 'custom-sidebar',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<h4 class="wpbf-widgettitle">',
        'after_title'   => '</h4>'
    ) );

}
add_action( 'widgets_init', 'prefix_custom_sidebar' );

// Replace the default sidebar with our new custom sidebar on all docs posts
function prefix_do_custom_sidebar( $sidebar ) {
// this statement works for custom post types
    if( is_singular( 'news' ) ) {
        $sidebar ='custom-sidebar';
    }
// this statement NOT works for the page which is displaying the posts, display the default sidebar instead
    elseif ( is_singular( 'na-midia' ) ) {
        $sidebar ='custom-sidebar';
    }

    return $sidebar;

}
add_filter( 'wpbf_do_sidebar', 'prefix_do_custom_sidebar' );

Undefined asked
2021-12-6
Write your answer



514
votes

Answer

Solution:

Solved!

elseif ( is_page ( 'na-midia' ) ) {
        $sidebar ='custom-sidebar';
    }
Write your answer




Share solution ↓

Additional Information:

Date the issue was resolved:
2021-12-6
Link To Source
Link To Answer People are also looking for solutions of the problem: invalid argument supplied for foreach() laravel

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Similar questions

Find the answer in similar questions on our website.

105 Adding PHP Page to Wordpress Template
17 php - Prestashop 1.6 - Show Customer Group in Account page (Front End)
64 php - Wordpress custom post status of "expired"
765 php - set og tags for homepage only
693 php - Wordpress get_posts not working correctly
537 Using PHP have a MySQL statement into multiple PHP variables
777 php - .htaccess ErrorDocument 404 dont open the page
623 php - How to change the content of a page with javascript based on select input?
99 php - how to pull mysql data using .ajax and populating a form with it
386 php - Laravel command every minute doesn't work

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.






About the technologies asked in this question

PHP

PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites. The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/


HTML

HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet. Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/



Welcome to programmierfrage.com

programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.

Get answers to specific questions

Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.

Help Others Solve Their Issues

Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.



Latest questions:

185 php - how to pull mysql data using .ajax and populating a form with it

218 PHP : Post get method, need some advice

683 c# equivalent of x php escape sequence?

279 php - Is switch always better than a lot of elseifs?

580 How to get all product in a father_id in php mysql

876 Am I dreaming or do carriage returns prevent PHP versions from seeing a code line?

66 php - Find total number of $count++ in while loop

12 php - Show a number to two decimal places

24 ruby - XPath to select between two HTML comments is not working?

263 apache - htaccess - append html or php based on URL

Users questions:

NEW

Rename existing images with keyword in WordPress PHP

NEW

codeigniter

NEW

Class "web_profiler.controller.profiler" does not exist after upgrading symfony 3.4 to 4.4 version

NEW

$charge = \Stripe\Charge::create(array( "amount" => 100, "currency" => "gbp", "source" => $token, "destination" => [ "amount" => 20, "account" => 'xxxxx', ], ));

NEW

Write a PHP program that will generate the JSON structure below. Second Step: Write a JAVASCRIPT program that will parse the JSON structure once the PHP program is called using AJAX. You may show your output on the body of the HTML document or in the console




PHP x 410847
Laravel x 36785
Yii x 3846
CodeIgniter x 9997
Symfony x 7793
CakePHP x 3085
Zend Framework x 1235
Phalcon x 300
FuelPHP x 47
Slim x 570
JavaScript x 36883
React x 550
Angular x 1121
Vue.js x 181
JQuery x 11108
Backbone.js x 21
Node.js x 463
Ember.js x 10
Meteor x 7
Polymer x 20
Aurelia x 1
MySQL x 39074
CSS x 2497
Bootstrap x 1603
Foundation x 84
UIkit x 4
Semantic UI x 2
Bulma x 2
Animate.css x 1
HTML x 20978



© 2021-2023 Programming problem solving site for beginners and advanced. Answers to questions related to coding.

E-mail: [email protected]

This site uses cookies. We use them to improve the performance of our website and your interaction with it. Confirm your consent by clicking OK


OK